]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Code cleanup: Implement proper assignment operator for HttpHeader.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 18 Feb 2011 04:44:02 +0000 (21:44 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 18 Feb 2011 04:44:02 +0000 (21:44 -0700)
Besides being the Right Thing, this helps classes that have HttpHeader data
members to avoid defining explicit assignment operators.

src/HttpHeader.cc
src/HttpHeader.h

index 057ac4af362f2de82b83cc6e6f1d0c5dc3fe6738..89f30209957eb9a8d4a076cdc1d9842cc13f11a7 100644 (file)
@@ -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;
 }
 
index e28545139cb56089b7ba4a96bbb3906e98875e8c..b35ab62147ae8012d95e65cfd355d66c36c39779 100644 (file)
@@ -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 &);
 };