@@ -66,7 +66,7 @@ Status ReadBlockFromFile(RandomAccessFile* file, const Footer& footer,
66
66
Status s = ReadBlockContents (file, footer, options, handle, &contents, env,
67
67
do_uncompress);
68
68
if (s.ok ()) {
69
- *result = new Block (contents);
69
+ *result = new Block (std::move ( contents) );
70
70
}
71
71
72
72
return s;
@@ -252,9 +252,6 @@ class HashIndexReader : public IndexReader {
252
252
&prefixes_meta_contents, env,
253
253
true /* do decompression */ );
254
254
if (!s.ok ()) {
255
- if (prefixes_contents.heap_allocated ) {
256
- delete[] prefixes_contents.data .data ();
257
- }
258
255
// TODO: log error
259
256
return Status::OK ();
260
257
}
@@ -269,7 +266,7 @@ class HashIndexReader : public IndexReader {
269
266
// TODO: log error
270
267
if (s.ok ()) {
271
268
new_index_reader->index_block_ ->SetBlockHashIndex (hash_index);
272
- new_index_reader->OwnPrefixesContents (prefixes_contents);
269
+ new_index_reader->OwnPrefixesContents (std::move ( prefixes_contents) );
273
270
}
274
271
} else {
275
272
BlockPrefixIndex* prefix_index = nullptr ;
@@ -283,18 +280,6 @@ class HashIndexReader : public IndexReader {
283
280
}
284
281
}
285
282
286
- // Always release prefix meta block
287
- if (prefixes_meta_contents.heap_allocated ) {
288
- delete[] prefixes_meta_contents.data .data ();
289
- }
290
-
291
- // Release prefix content block if we don't own it.
292
- if (!new_index_reader->own_prefixes_contents_ ) {
293
- if (prefixes_contents.heap_allocated ) {
294
- delete[] prefixes_contents.data .data ();
295
- }
296
- }
297
-
298
283
return Status::OK ();
299
284
}
300
285
@@ -314,24 +299,18 @@ class HashIndexReader : public IndexReader {
314
299
private:
315
300
HashIndexReader (const Comparator* comparator, Block* index_block)
316
301
: IndexReader(comparator),
317
- index_block_ (index_block),
318
- own_prefixes_contents_(false ) {
302
+ index_block_ (index_block) {
319
303
assert (index_block_ != nullptr );
320
304
}
321
305
322
306
~HashIndexReader () {
323
- if (own_prefixes_contents_ && prefixes_contents_.heap_allocated ) {
324
- delete[] prefixes_contents_.data .data ();
325
- }
326
307
}
327
308
328
- void OwnPrefixesContents (const BlockContents& prefixes_contents) {
329
- prefixes_contents_ = prefixes_contents;
330
- own_prefixes_contents_ = true ;
309
+ void OwnPrefixesContents (BlockContents&& prefixes_contents) {
310
+ prefixes_contents_ = std::move (prefixes_contents);
331
311
}
332
312
333
313
std::unique_ptr<Block> index_block_;
334
- bool own_prefixes_contents_;
335
314
BlockContents prefixes_contents_;
336
315
};
337
316
@@ -677,7 +656,7 @@ Status BlockBasedTable::GetDataBlockFromCache(
677
656
678
657
// Insert uncompressed block into block cache
679
658
if (s.ok ()) {
680
- block->value = new Block (contents); // uncompressed block
659
+ block->value = new Block (std::move ( contents) ); // uncompressed block
681
660
assert (block->value ->compression_type () == kNoCompression );
682
661
if (block_cache != nullptr && block->value ->cachable () &&
683
662
read_options.fill_cache ) {
@@ -715,7 +694,7 @@ Status BlockBasedTable::PutDataBlockToCache(
715
694
}
716
695
717
696
if (raw_block->compression_type () != kNoCompression ) {
718
- block->value = new Block (contents); // uncompressed block
697
+ block->value = new Block (std::move ( contents) ); // uncompressed block
719
698
} else {
720
699
block->value = raw_block;
721
700
raw_block = nullptr ;
@@ -768,15 +747,14 @@ FilterBlockReader* BlockBasedTable::ReadFilter(
768
747
assert (rep->filter_policy );
769
748
if (kFilterBlockPrefix == filter_block_prefix) {
770
749
return new BlockBasedFilterBlockReader (rep->ioptions .prefix_extractor ,
771
- rep->table_options , block. data , block. heap_allocated );
750
+ rep->table_options , std::move ( block) );
772
751
} else if (kFullFilterBlockPrefix == filter_block_prefix) {
773
752
auto filter_bits_reader = rep->filter_policy ->
774
753
GetFilterBitsReader (block.data );
775
754
776
755
if (filter_bits_reader != nullptr ) {
777
756
return new FullFilterBlockReader (rep->ioptions .prefix_extractor ,
778
- rep->table_options , block.data , filter_bits_reader,
779
- block.heap_allocated );
757
+ rep->table_options , std::move (block), filter_bits_reader);
780
758
}
781
759
}
782
760
return nullptr ;
0 commit comments