Commit 96f9e38d authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Improve IOBuf::clone and IOBuf::cloneOne() perf

Summary: Improve IOBuf::clone and IOBuf::cloneOne() perf

Reviewed By: yfeldblum

Differential Revision: D20882203

fbshipit-source-id: ce37c2bf3c0fbdbe3c316856dc431a0108e4b9bf
parent dc0571b7
...@@ -600,11 +600,26 @@ void IOBuf::prependChain(unique_ptr<IOBuf>&& iobuf) { ...@@ -600,11 +600,26 @@ void IOBuf::prependChain(unique_ptr<IOBuf>&& iobuf) {
} }
unique_ptr<IOBuf> IOBuf::clone() const { unique_ptr<IOBuf> IOBuf::clone() const {
return std::make_unique<IOBuf>(cloneAsValue()); auto tmp = cloneOne();
for (IOBuf* current = next_; current != this; current = current->next_) {
tmp->prependChain(current->cloneOne());
}
return tmp;
} }
unique_ptr<IOBuf> IOBuf::cloneOne() const { unique_ptr<IOBuf> IOBuf::cloneOne() const {
return std::make_unique<IOBuf>(cloneOneAsValue()); if (SharedInfo* info = sharedInfo()) {
info->refcount.fetch_add(1, std::memory_order_acq_rel);
}
return std::unique_ptr<IOBuf>(new IOBuf(
InternalConstructor(),
flagsAndSharedInfo_,
buf_,
capacity_,
data_,
length_));
} }
unique_ptr<IOBuf> IOBuf::cloneCoalesced() const { unique_ptr<IOBuf> IOBuf::cloneCoalesced() const {
......
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