From: Alex Rousskov Date: Thu, 3 Nov 2016 13:57:02 +0000 (+1300) Subject: Optimize appending to empty SBufs, a common use case. X-Git-Tag: SQUID_4_0_17~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7378e715141a56527221d8212901c35c8360a95;p=thirdparty%2Fsquid.git Optimize appending to empty SBufs, a common use case. Most appends start with an empty buffer. Some append only once. There is no reason to allocate new memory for that first append or force the appender to write code to optimize that first append. Why also check that SBuf has never been configured or altered then? To preserve pre-allocated SBufs, such as those [ab]used as I/O buffers. --- diff --git a/src/sbuf/SBuf.cc b/src/sbuf/SBuf.cc index c981cdc716..663477fc5b 100644 --- a/src/sbuf/SBuf.cc +++ b/src/sbuf/SBuf.cc @@ -187,6 +187,9 @@ SBuf::clear() SBuf& SBuf::append(const SBuf &S) { + if (isEmpty() && store_ == GetStorePrototype()) + return (*this = S); // optimization: avoid needless copying + const Locker blobKeeper(this, S.buf()); return lowAppend(S.buf(), S.length()); }