]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Code cleanup: Proper assignment and copying of HttpHeader.
authorAlex Rousskov <rousskov@measurement-factory.com>
Mon, 21 Feb 2011 04:31:06 +0000 (21:31 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Mon, 21 Feb 2011 04:31:06 +0000 (21:31 -0700)
Besides being the Right Thing, having correct assignment operator and
copy constructor helps classes that have HttpHeader data members to
avoid defining explicit assignment operators and copy constructors.

Also adds forgotten reset of "len" in the clean() method.

Other polishing touches. HttpHeader::reset() is now a tiny bit faster.

No runtime changes expected.

src/HttpHeader.cc
src/HttpHeader.h

index 3c5ab7da7ab224e9b84563c3c545be2303f3ffd4..82f2c6b8df700a8255c4158b01424d23a6b0b674 100644 (file)
@@ -383,18 +383,37 @@ 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();
 }
 
+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 +456,7 @@ HttpHeader::clean()
     }
     entries.clean();
     httpHeaderMaskInit(&mask, 0);
+    len = 0;
     PROF_stop(HttpHeaderClean);
 }
 
@@ -500,10 +520,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;
 }
 
index e28545139cb56089b7ba4a96bbb3906e98875e8c..a9cf983be19e379e3873674582db4a27d6a55e3f 100644 (file)
@@ -205,8 +205,12 @@ class HttpHeader
 
 public:
     HttpHeader();
-    HttpHeader(http_hdr_owner_type const &owner);
+    explicit HttpHeader(const http_hdr_owner_type owner);
+    HttpHeader(const HttpHeader &other);
     ~HttpHeader();
+
+    HttpHeader &operator =(const HttpHeader &other);
+
     /* Interface functions */
     void clean();
     void append(const HttpHeader * src);
@@ -271,10 +275,6 @@ protected:
 
 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 &);
 };