Use std::make_unique when possible (#10578)

Summary: Pull Request resolved: https://github.com/facebook/rocksdb/pull/10578

Test Plan: make check

Reviewed By: ajkr

Differential Revision: D39064748

Pulled By: riversand963

fbshipit-source-id: c7c135b7b713608edb14614846050ece6d4cc59d
main
Yanqin Jin 2 years ago committed by Facebook GitHub Bot
parent e484b81eee
commit 7c0838e65e
  1. 27
      db/range_del_aggregator.cc
  2. 10
      db/range_del_aggregator.h
  3. 9
      db/range_tombstone_fragmenter.cc

@ -82,12 +82,6 @@ bool TruncatedRangeDelIterator::Valid() const {
icmp_->Compare(iter_->parsed_start_key(), *largest_) < 0); icmp_->Compare(iter_->parsed_start_key(), *largest_) < 0);
} }
void TruncatedRangeDelIterator::Next() { iter_->TopNext(); }
void TruncatedRangeDelIterator::Prev() { iter_->TopPrev(); }
void TruncatedRangeDelIterator::InternalNext() { iter_->Next(); }
// NOTE: target is a user key // NOTE: target is a user key
void TruncatedRangeDelIterator::Seek(const Slice& target) { void TruncatedRangeDelIterator::Seek(const Slice& target) {
if (largest_ != nullptr && if (largest_ != nullptr &&
@ -149,9 +143,8 @@ TruncatedRangeDelIterator::SplitBySnapshot(
std::for_each( std::for_each(
split_untruncated_iters.begin(), split_untruncated_iters.end(), split_untruncated_iters.begin(), split_untruncated_iters.end(),
[&](FragmentedIterPair& iter_pair) { [&](FragmentedIterPair& iter_pair) {
std::unique_ptr<TruncatedRangeDelIterator> truncated_iter( auto truncated_iter = std::make_unique<TruncatedRangeDelIterator>(
new TruncatedRangeDelIterator(std::move(iter_pair.second), icmp_, std::move(iter_pair.second), icmp_, smallest_ikey_, largest_ikey_);
smallest_ikey_, largest_ikey_));
split_truncated_iters.emplace(iter_pair.first, split_truncated_iters.emplace(iter_pair.first,
std::move(truncated_iter)); std::move(truncated_iter));
}); });
@ -322,9 +315,8 @@ void ReadRangeDelAggregator::AddTombstones(
if (input_iter == nullptr || input_iter->empty()) { if (input_iter == nullptr || input_iter->empty()) {
return; return;
} }
rep_.AddTombstones( rep_.AddTombstones(std::make_unique<TruncatedRangeDelIterator>(
std::unique_ptr<TruncatedRangeDelIterator>(new TruncatedRangeDelIterator( std::move(input_iter), icmp_, smallest, largest));
std::move(input_iter), icmp_, smallest, largest)));
} }
bool ReadRangeDelAggregator::ShouldDeleteImpl(const ParsedInternalKey& parsed, bool ReadRangeDelAggregator::ShouldDeleteImpl(const ParsedInternalKey& parsed,
@ -471,19 +463,16 @@ CompactionRangeDelAggregator::NewIterator(const Slice* lower_bound,
const Slice* upper_bound, const Slice* upper_bound,
bool upper_bound_inclusive) { bool upper_bound_inclusive) {
InvalidateRangeDelMapPositions(); InvalidateRangeDelMapPositions();
std::unique_ptr<TruncatedRangeDelMergingIter> merging_iter( auto merging_iter = std::make_unique<TruncatedRangeDelMergingIter>(
new TruncatedRangeDelMergingIter(icmp_, lower_bound, upper_bound, icmp_, lower_bound, upper_bound, upper_bound_inclusive, parent_iters_);
upper_bound_inclusive, parent_iters_));
auto fragmented_tombstone_list = auto fragmented_tombstone_list =
std::make_shared<FragmentedRangeTombstoneList>( std::make_shared<FragmentedRangeTombstoneList>(
std::move(merging_iter), *icmp_, true /* for_compaction */, std::move(merging_iter), *icmp_, true /* for_compaction */,
*snapshots_); *snapshots_);
return std::unique_ptr<FragmentedRangeTombstoneIterator>( return std::make_unique<FragmentedRangeTombstoneIterator>(
new FragmentedRangeTombstoneIterator( fragmented_tombstone_list, *icmp_, kMaxSequenceNumber /* upper_bound */);
fragmented_tombstone_list, *icmp_,
kMaxSequenceNumber /* upper_bound */));
} }
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -38,10 +38,10 @@ class TruncatedRangeDelIterator {
bool Valid() const; bool Valid() const;
void Next(); void Next() { iter_->TopNext(); }
void Prev(); void Prev() { iter_->TopPrev(); }
void InternalNext(); void InternalNext() { iter_->Next(); }
// Seeks to the tombstone with the highest visible sequence number that covers // Seeks to the tombstone with the highest visible sequence number that covers
// target (a user key). If no such tombstone exists, the position will be at // target (a user key). If no such tombstone exists, the position will be at
@ -281,11 +281,11 @@ class RangeDelAggregator {
const InternalKey* smallest = nullptr, const InternalKey* smallest = nullptr,
const InternalKey* largest = nullptr) = 0; const InternalKey* largest = nullptr) = 0;
bool ShouldDelete(const Slice& key, RangeDelPositioningMode mode) { bool ShouldDelete(const Slice& ikey, RangeDelPositioningMode mode) {
ParsedInternalKey parsed; ParsedInternalKey parsed;
Status pik_status = Status pik_status =
ParseInternalKey(key, &parsed, false /* log_err_key */); // TODO ParseInternalKey(ikey, &parsed, false /* log_err_key */); // TODO
assert(pik_status.ok()); assert(pik_status.ok());
if (!pik_status.ok()) { if (!pik_status.ok()) {
return false; return false;

@ -67,8 +67,8 @@ FragmentedRangeTombstoneList::FragmentedRangeTombstoneList(
unfragmented_tombstones->value().size()); unfragmented_tombstones->value().size());
} }
// VectorIterator implicitly sorts by key during construction. // VectorIterator implicitly sorts by key during construction.
auto iter = std::unique_ptr<VectorIterator>( auto iter = std::make_unique<VectorIterator>(std::move(keys),
new VectorIterator(std::move(keys), std::move(values), &icmp)); std::move(values), &icmp);
FragmentTombstones(std::move(iter), icmp, for_compaction, snapshots); FragmentTombstones(std::move(iter), icmp, for_compaction, snapshots);
} }
@ -433,9 +433,8 @@ FragmentedRangeTombstoneIterator::SplitBySnapshot(
upper = snapshots[i]; upper = snapshots[i];
} }
if (tombstones_->ContainsRange(lower, upper)) { if (tombstones_->ContainsRange(lower, upper)) {
splits.emplace(upper, std::unique_ptr<FragmentedRangeTombstoneIterator>( splits.emplace(upper, std::make_unique<FragmentedRangeTombstoneIterator>(
new FragmentedRangeTombstoneIterator( tombstones_, *icmp_, upper, lower));
tombstones_, *icmp_, upper, lower)));
} }
lower = upper + 1; lower = upper + 1;
} }

Loading…
Cancel
Save