From: Alex Rousskov Date: Fri, 18 Feb 2011 04:44:02 +0000 (-0700) Subject: Code cleanup: Implement proper assignment operator for HttpHeader. X-Git-Tag: take03~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0018034b08079bc2c736ec220c34dab9e298a58;p=thirdparty%2Fsquid.git Code cleanup: Implement proper assignment operator for HttpHeader. Besides being the Right Thing, this helps classes that have HttpHeader data members to avoid defining explicit assignment operators. --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 057ac4af36..89f3020995 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -395,6 +395,19 @@ HttpHeader::~HttpHeader() clean(); } +const HttpHeader & +HttpHeader::operator =(const HttpHeader &other) +{ + if (this != &other) { + // we do not really care, but the caller probably does + assert(owner == other.owner); + clean(); + update(&other, NULL); // will update the mask as well + len = other.len; + } + return *this; +} + void HttpHeader::clean() { @@ -437,6 +450,7 @@ HttpHeader::clean() } entries.clean(); httpHeaderMaskInit(&mask, 0); + len = 0; // TODO: this line was missing for a while; do we need len at all? PROF_stop(HttpHeaderClean); } @@ -500,10 +514,7 @@ HttpHeader::update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask) int HttpHeader::reset() { - http_hdr_owner_type ho; - ho = owner; clean(); - *this = HttpHeader(ho); return 0; } diff --git a/src/HttpHeader.h b/src/HttpHeader.h index e28545139c..b35ab62147 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -207,6 +207,9 @@ public: HttpHeader(); HttpHeader(http_hdr_owner_type const &owner); ~HttpHeader(); + + const HttpHeader &operator =(const HttpHeader &other); + /* Interface functions */ void clean(); void append(const HttpHeader * src); @@ -273,8 +276,6 @@ private: HttpHeaderEntry *findLastEntry(http_hdr_type id) const; /// Made it non-copyable. Our destructor is a bit nasty... HttpHeader(const HttpHeader &); - //assignment is used by the reset method, can't block it.. - //const HttpHeader operator=(const HttpHeader &); };