Skip to content

Commit

Permalink
optimize PTreeFinger copy constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
sears committed Apr 16, 2020
1 parent 943e942 commit fe6054c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fdbclient/VersionedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,27 @@ namespace PTreeImpl {
public:
PTreeFinger() {}

// Explicit copy constructors ensure we copy the live values in entries_.
PTreeFinger(PTreeFinger const & f) {
*this = f;
}

PTreeFinger(PTreeFinger && f) {
*this = f;
}

PTreeFinger & operator=(PTreeFinger const & f) {
size_ = f.size_;
std::copy(f.entries_, f.entries_ + size_, entries_);
return *this;
}

PTreeFinger & operator=(PTreeFinger && f) {
size_ = std::exchange(f.size_, 0);
std::copy(f.entries_, f.entries_ + size_, entries_);
return *this;
}

size_t size() const { return size_; }
void push_back(PTree<T> const* node) { this->push_back(node, false); }
PTree<T> const* back() const { return entries_[size_ - 1].node; }
Expand Down

0 comments on commit fe6054c

Please sign in to comment.