]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
MemBuf may be empty when items are append()'ed.
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 29 Jun 2008 11:20:14 +0000 (23:20 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 29 Jun 2008 11:20:14 +0000 (23:20 +1200)
- 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()

src/MemBuf.cc

index b08cb7d8a77782f9143d43a1b4daab4112a3de2b..2c168e61d8a5bc2b857502b81b4492c9e3af330f 100644 (file)
@@ -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);