From: Alex Rousskov Date: Fri, 18 Feb 2011 05:05:28 +0000 (-0700) Subject: Code cleanup: Implement proper copy-constructor for HttpHeader. Polished. X-Git-Tag: take03~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b779a9250b3edbb96189bc12f510ce2532488b82;p=thirdparty%2Fsquid.git Code cleanup: Implement proper copy-constructor for HttpHeader. Polished. Besides being the Right Thing, this helps classes that have HttpHeader data members to avoid defining explicit copy constructors. Also fixed blindly copied assignment operator profile and polished another constructor to prevent implicit integer-to-HttpHeader conversion. --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 89f3020995..8627fb064d 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -383,19 +383,25 @@ HttpHeader::HttpHeader() : owner (hoNone), len (0) httpHeaderMaskInit(&mask, 0); } -HttpHeader::HttpHeader(http_hdr_owner_type const &anOwner) : owner (anOwner), len (0) +HttpHeader::HttpHeader(const http_hdr_owner_type anOwner): owner(anOwner), len(0) { assert(anOwner > hoNone && anOwner <= hoReply); debugs(55, 7, "init-ing hdr: " << this << " owner: " << owner); httpHeaderMaskInit(&mask, 0); } +HttpHeader::HttpHeader(const HttpHeader &other): owner(other.owner), len(other.len) +{ + httpHeaderMaskInit(&mask, 0); + update(&other, NULL); // will update the mask as well +} + HttpHeader::~HttpHeader() { clean(); } -const HttpHeader & +HttpHeader & HttpHeader::operator =(const HttpHeader &other) { if (this != &other) { diff --git a/src/HttpHeader.h b/src/HttpHeader.h index b35ab62147..a9cf983be1 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -205,10 +205,11 @@ class HttpHeader public: HttpHeader(); - HttpHeader(http_hdr_owner_type const &owner); + explicit HttpHeader(const http_hdr_owner_type owner); + HttpHeader(const HttpHeader &other); ~HttpHeader(); - const HttpHeader &operator =(const HttpHeader &other); + HttpHeader &operator =(const HttpHeader &other); /* Interface functions */ void clean(); @@ -274,8 +275,6 @@ protected: private: HttpHeaderEntry *findLastEntry(http_hdr_type id) const; - /// Made it non-copyable. Our destructor is a bit nasty... - HttpHeader(const HttpHeader &); };