From: adrian <> Date: Mon, 2 Oct 2006 15:52:06 +0000 (+0000) Subject: Reduce a couple of obvious string copies by using String references and filling them. X-Git-Tag: SQUID_3_0_PRE5~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35b88ed28f3547ed0e25aa7a56badd410ae519c1;p=thirdparty%2Fsquid.git Reduce a couple of obvious string copies by using String references and filling them. --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index bd12f0efdc..c12348d8df 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.cc,v 1.126 2006/09/28 07:13:12 adrian Exp $ + * $Id: HttpHeader.cc,v 1.127 2006/10/02 09:52:06 adrian Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -628,9 +628,12 @@ HttpHeader::packInto(Packer * p) const assert(p); debug(55, 7) ("packing hdr: (%p)\n", this); /* pack all entries one by one */ - while ((e = getEntry(&pos))) e->packInto(p); + + /* Pack in the "special" entries */ + + /* Cache-Control */ } /* returns next valid entry */ @@ -819,6 +822,37 @@ HttpHeader::insertEntry(HttpHeaderEntry * e) len += e->name.size() + 2 + e->value.size() + 2; } +bool +HttpHeader::getList(http_hdr_type id, String *s) const +{ + HttpHeaderEntry *e; + HttpHeaderPos pos = HttpHeaderInitPos; + debug(55, 9) ("%p: joining for id %d\n", this, id); + /* only fields from ListHeaders array can be "listed" */ + assert(CBIT_TEST(ListHeadersMask, id)); + + if (!CBIT_TEST(mask, id)) + return false; + + while ((e = getEntry(&pos))) { + if (e->id == id) + strListAdd(s, e->value.buf(), ','); + } + + /* + * note: we might get an empty (size==0) string if there was an "empty" + * header. This results in an empty length String, which may have a NULL + * buffer. + */ + /* temporary warning: remove it? (Is it useful for diagnostics ?) */ + if (!s->size()) + debugs(55, 3, "empty list header: " << Headers[id].name << "(" << id << ")"); + else + debugs(55, 6, this << ": joined for id " << id << ": " << s); + + return true; +} + /* return a list of entries with the same id separated by ',' and ws */ String HttpHeader::getList(http_hdr_type id) const @@ -1161,8 +1195,9 @@ HttpHeader::getCc() const if (!CBIT_TEST(mask, HDR_CACHE_CONTROL)) return NULL; + PROF_start(HttpHeader_getCc); - s = getList(HDR_CACHE_CONTROL); + getList(HDR_CACHE_CONTROL, &s); cc = httpHdrCcParseCreate(&s); @@ -1173,7 +1208,7 @@ HttpHeader::getCc() const httpHeaderNoteParsedEntry(HDR_CACHE_CONTROL, s, !cc); - s.clean(); + PROF_stop(HttpHeader_getCc); return cc; } @@ -1203,7 +1238,9 @@ HttpHeader::getSc() const if (!CBIT_TEST(mask, HDR_SURROGATE_CONTROL)) return NULL; - String s (getList(HDR_SURROGATE_CONTROL)); + String s; + + (void) getList(HDR_SURROGATE_CONTROL, &s); HttpHdrSc *sc = httpHdrScParseCreate(&s); @@ -1662,7 +1699,9 @@ HttpHeader::removeConnectionHeaderEntries() { if (has(HDR_CONNECTION)) { /* anything that matches Connection list member will be deleted */ - String strConnection = getList(HDR_CONNECTION); + String strConnection; + + (void) getList(HDR_CONNECTION, &strConnection); const HttpHeaderEntry *e; HttpHeaderPos pos = HttpHeaderInitPos; /* @@ -1680,6 +1719,5 @@ HttpHeader::removeConnectionHeaderEntries() } delById(HDR_CONNECTION); - strConnection.clean(); } } diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 4d56a5ee82..35aae1d276 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.h,v 1.17 2006/06/07 22:39:33 hno Exp $ + * $Id: HttpHeader.h,v 1.18 2006/10/02 09:52:06 adrian Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -211,6 +211,7 @@ public: void addEntry(HttpHeaderEntry * e); void insertEntry(HttpHeaderEntry * e); String getList(http_hdr_type id) const; + bool getList(http_hdr_type id, String *s) const; String getStrOrList(http_hdr_type id) const; String getByName(const char *name) const; String getByNameListMember(const char *name, const char *member, const char separator) const;