Skip to content

Commit

Permalink
Use rvalue reference for IOBuf value in fill request
Browse files Browse the repository at this point in the history
Summary: IOBuf in value field of fill request is being passed around as a const reference. This diff changes this to a rvalue reference, so as to avoid wasteful refcount increment of IOBuf.

Reviewed By: alikhtarov

Differential Revision: D63415040

fbshipit-source-id: 5a95502fa1d82224a03cf9e9a7f1d5dfdf08f44e
  • Loading branch information
Yu Sui authored and facebook-github-bot committed Oct 1, 2024
1 parent 699f085 commit 914a238
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions mcrouter/lib/IOBufUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ folly::StringPiece coalesceAndGetRange(
return coalesceAndGetRange(*buf);
}

void copyInto(char* raw, const folly::IOBuf& buf) {
auto cur = &buf;
void copyIntoInternal(char* raw, const folly::IOBuf* bufPtr) {
auto cur = bufPtr;
auto next = cur->next();
do {
if (cur->data()) {
Expand All @@ -67,7 +67,15 @@ void copyInto(char* raw, const folly::IOBuf& buf) {
}
cur = next;
next = next->next();
} while (cur != &buf);
} while (cur != bufPtr);
}

void copyInto(char* raw, const folly::IOBuf& buf) {
copyIntoInternal(raw, &buf);
}

void copyInto(char* raw, folly::IOBuf&& buf) {
copyIntoInternal(raw, &buf);
}

namespace {
Expand Down
1 change: 1 addition & 0 deletions mcrouter/lib/IOBufUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ folly::StringPiece coalesceAndGetRange(
apache::thrift::field_ref<const folly::IOBuf&> buf);

void copyInto(char* raw, const folly::IOBuf& buf);
void copyInto(char* raw, folly::IOBuf&& buf);

template <typename InputIterator>
folly::IOBuf concatAll(InputIterator begin, InputIterator end) {
Expand Down

0 comments on commit 914a238

Please sign in to comment.