Commit e941e2e0 authored by Stepan Palamarchuk's avatar Stepan Palamarchuk Committed by Facebook Github Bot

Slight optimization of append logic

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
parent 6a9e877e
......@@ -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();
}
}
......
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