@@ -260,23 +260,19 @@ Status PlainTableReader::PopulateIndexRecordList(
260260 return s;
261261}
262262
263- void PlainTableReader::AllocateAndFillBloom (
264- int bloom_bits_per_key, int num_prefixes, size_t huge_page_tlb_size,
265- std::vector<uint32_t >* prefix_hashes) {
266- if (!IsTotalOrderMode ()) {
267- uint32_t bloom_total_bits = num_prefixes * bloom_bits_per_key;
268- if (bloom_total_bits > 0 ) {
269- enable_bloom_ = true ;
270- bloom_.SetTotalBits (&arena_, bloom_total_bits, ioptions_.bloom_locality ,
271- huge_page_tlb_size, ioptions_.info_log );
272- FillBloom (prefix_hashes);
273- }
263+ void PlainTableReader::AllocateBloom (int bloom_bits_per_key, int num_keys,
264+ size_t huge_page_tlb_size) {
265+ uint32_t bloom_total_bits = num_keys * bloom_bits_per_key;
266+ if (bloom_total_bits > 0 ) {
267+ enable_bloom_ = true ;
268+ bloom_.SetTotalBits (&arena_, bloom_total_bits, ioptions_.bloom_locality ,
269+ huge_page_tlb_size, ioptions_.info_log );
274270 }
275271}
276272
277- void PlainTableReader::FillBloom (std::vector<uint32_t >* prefix_hashes) {
273+ void PlainTableReader::FillBloom (const std::vector<uint32_t >& prefix_hashes) {
278274 assert (bloom_.IsInitialized ());
279- for (auto prefix_hash : * prefix_hashes) {
275+ for (const auto prefix_hash : prefix_hashes) {
280276 bloom_.AddHash (prefix_hash);
281277 }
282278}
@@ -354,14 +350,9 @@ Status PlainTableReader::PopulateIndex(TableProperties* props,
354350 if (!index_in_file) {
355351 // Allocate bloom filter here for total order mode.
356352 if (IsTotalOrderMode ()) {
357- uint32_t num_bloom_bits =
358- static_cast <uint32_t >(table_properties_->num_entries ) *
359- bloom_bits_per_key;
360- if (num_bloom_bits > 0 ) {
361- enable_bloom_ = true ;
362- bloom_.SetTotalBits (&arena_, num_bloom_bits, ioptions_.bloom_locality ,
363- huge_page_tlb_size, ioptions_.info_log );
364- }
353+ AllocateBloom (bloom_bits_per_key,
354+ static_cast <uint32_t >(table_properties_->num_entries ),
355+ huge_page_tlb_size);
365356 }
366357 } else if (bloom_in_file) {
367358 enable_bloom_ = true ;
@@ -377,8 +368,7 @@ Status PlainTableReader::PopulateIndex(TableProperties* props,
377368 }
378369 // cast away const qualifier, because bloom_ won't be changed
379370 bloom_.SetRawData (
380- const_cast <unsigned char *>(
381- reinterpret_cast <const unsigned char *>(bloom_block->data ())),
371+ const_cast <char *>(bloom_block->data ()),
382372 static_cast <uint32_t >(bloom_block->size ()) * 8 , num_blocks);
383373 } else {
384374 // Index in file but no bloom in file. Disable bloom filter in this case.
@@ -392,6 +382,7 @@ Status PlainTableReader::PopulateIndex(TableProperties* props,
392382
393383 std::vector<uint32_t > prefix_hashes;
394384 if (!index_in_file) {
385+ // Populates _bloom if enabled (total order mode)
395386 s = PopulateIndexRecordList (&index_builder, &prefix_hashes);
396387 if (!s.ok ()) {
397388 return s;
@@ -404,10 +395,15 @@ Status PlainTableReader::PopulateIndex(TableProperties* props,
404395 }
405396
406397 if (!index_in_file) {
407- // Calculated bloom filter size and allocate memory for
408- // bloom filter based on the number of prefixes, then fill it.
409- AllocateAndFillBloom (bloom_bits_per_key, index_.GetNumPrefixes (),
410- huge_page_tlb_size, &prefix_hashes);
398+ if (!IsTotalOrderMode ()) {
399+ // Calculated bloom filter size and allocate memory for
400+ // bloom filter based on the number of prefixes, then fill it.
401+ AllocateBloom (bloom_bits_per_key, index_.GetNumPrefixes (),
402+ huge_page_tlb_size);
403+ if (enable_bloom_) {
404+ FillBloom (prefix_hashes);
405+ }
406+ }
411407 }
412408
413409 // Fill two table properties.
0 commit comments