Commit 6a6e02c2 authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook GitHub Bot

Avoid a shared_ptr copy in ConcurrentSkipList::Skipper construction

Summary:
Make `Skipper` accept the `shared_ptr` by value, like `Accessor` does, so we can avoid the copy.

Also expose the accessor, so after we handed over the `shared_ptr` we can still retain access to the list.

Reviewed By: philippv

Differential Revision: D29464861

fbshipit-source-id: 75e93f0e72c4b8a2635d25e5e7860f27aec2a0a5
parent 5b5e814e
......@@ -173,7 +173,7 @@ class ConcurrentSkipList {
head_(NodeType::create(recycler_.alloc(), height, value_type(), true)) {
}
// Convenient function to get an Accessor to a new instance.
// Convenience function to get an Accessor to a new instance.
static Accessor create(int height, const NodeAlloc& alloc) {
return Accessor(createInstance(height, alloc));
}
......@@ -719,7 +719,8 @@ class ConcurrentSkipList<T, Comp, NodeAlloc, MAX_HEIGHT>::Skipper {
typedef T* pointer;
typedef ptrdiff_t difference_type;
Skipper(const std::shared_ptr<SkipListType>& skipList) : accessor_(skipList) {
Skipper(std::shared_ptr<SkipListType> skipList)
: accessor_(std::move(skipList)) {
init();
}
......@@ -752,6 +753,9 @@ class ConcurrentSkipList<T, Comp, NodeAlloc, MAX_HEIGHT>::Skipper {
return *this;
}
Accessor& accessor() { return accessor_; }
const Accessor& accessor() const { return accessor_; }
bool good() const { return succs_[0] != nullptr; }
int maxLayer() const { return headHeight_ - 1; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment