From: Amos Jeffries Date: Sun, 29 Jun 2008 11:20:14 +0000 (+1200) Subject: MemBuf may be empty when items are append()'ed. X-Git-Tag: SQUID_3_1_0_1~49^2~187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aeb1200cb28f273ac5804469ae93e7aac1ab2065;p=thirdparty%2Fsquid.git MemBuf may be empty when items are append()'ed. - Fixes append() to handle the side case where the buffer is empty just after initialization and before any calls to Printf() This allows several performance optimisations to follow, since append() utilizes fast memcpy() and Printf() uses the slower snprintf() --- diff --git a/src/MemBuf.cc b/src/MemBuf.cc index b08cb7d8a7..2c168e61d8 100644 --- a/src/MemBuf.cc +++ b/src/MemBuf.cc @@ -226,13 +226,19 @@ void MemBuf::consume(mb_size_t shiftSize) PROF_stop(MemBuf_consume); } -// calls memcpy, appends exactly size bytes, extends buffer if needed +/** + * calls memcpy, appends exactly size bytes, + * extends buffer or creates buffer if needed. + */ void MemBuf::append(const char *newContent, mb_size_t sz) { assert(sz >= 0); - assert(buf); assert(!stolen); /* not frozen */ + if(!buf) { + grow(sz+1, MEM_BUF_MAX_SIZE); + } + PROF_start(MemBuf_append); if (sz > 0) { if (size + sz + 1 > capacity) @@ -247,7 +253,7 @@ void MemBuf::append(const char *newContent, mb_size_t sz) PROF_stop(MemBuf_append); } -// updates content size after external append +/// updates content size after external append void MemBuf::appended(mb_size_t sz) { assert(size + sz <= capacity);