Decide whether it's worth using a bulk filter over the given data area
| 56 | |
| 57 | // Decide whether it's worth using a bulk filter over the given data area |
| 58 | bool ShouldUseBulkFilter(const char* data, const char* data_end) { |
| 59 | if (!bulk_filter_.CanUseOnBlock( |
| 60 | std::string_view(data, static_cast<size_t>(data_end - data)))) { |
| 61 | return false; |
| 62 | } |
| 63 | constexpr int32_t kWordSize = static_cast<int32_t>(sizeof(BulkWordType)); |
| 64 | |
| 65 | // Only probe the 32 first words and assume they are representative of the rest |
| 66 | const int64_t n_words = std::min<int64_t>(32, (data_end - data) / kWordSize); |
| 67 | int64_t n_skips = 0; |
| 68 | const auto words = reinterpret_cast<const BulkWordType*>(data); |
| 69 | for (int64_t i = 0; i < n_words - 3; i += 4) { |
| 70 | const auto a = words[i + 0]; |
| 71 | const auto b = words[i + 1]; |
| 72 | const auto c = words[i + 2]; |
| 73 | const auto d = words[i + 3]; |
| 74 | n_skips += !bulk_filter_.Matches(a) + !bulk_filter_.Matches(b) + |
| 75 | !bulk_filter_.Matches(c) + !bulk_filter_.Matches(d); |
| 76 | } |
| 77 | return (n_skips * 4 + 1 >= n_words); |
| 78 | } |
| 79 | |
| 80 | template <bool UseBulkFilter = true> |
| 81 | const char* ReadLine(const char* data, const char* data_end) { |
no test coverage detected