Skip to content

Commit

Permalink
Slight optimization of append logic
Browse files Browse the repository at this point in the history
Summary:
1) There's no need to exit the loop if we encounter and IOBuf of length 0.
2) We should do `n <= tailroom()` instead of `n < tailroom()`.

Reviewed By: yfeldblum

Differential Revision: D14715582

fbshipit-source-id: 9a30454bd536929414f7c9013dbcf6e59e6e7f2c
  • Loading branch information
spalamarchuk authored and facebook-github-bot committed Apr 2, 2019
1 parent 6a9e877 commit e941e2e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions folly/io/IOBufQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ void appendToChain(unique_ptr<IOBuf>& dst, unique_ptr<IOBuf>&& src, bool pack) {
// joining two IOBufQueues together.
size_t copyRemaining = MAX_PACK_COPY;
std::size_t n;
while (src && (n = src->length()) < copyRemaining &&
n < tail->tailroom() && n > 0) {
memcpy(tail->writableTail(), src->data(), n);
tail->append(n);
copyRemaining -= n;
while (src && (n = src->length()) <= copyRemaining &&
n <= tail->tailroom()) {
if (n > 0) {
memcpy(tail->writableTail(), src->data(), n);
tail->append(n);
copyRemaining -= n;
}
src = src->pop();
}
}
Expand Down

0 comments on commit e941e2e

Please sign in to comment.