]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Optimize appending to empty SBufs, a common use case.
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 3 Nov 2016 13:57:02 +0000 (02:57 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 3 Nov 2016 13:57:02 +0000 (02:57 +1300)
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.

src/sbuf/SBuf.cc

index c981cdc71656807cc1026ef7ebff614e8c7d2ed3..663477fc5b80ca5fa5c59d0fb26dee839b843b01 100644 (file)
@@ -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());
 }