[squid-dev] [PATCH] Drop some CbDataList

Amos Jeffries squid3 at treenet.co.nz
Mon Nov 10 13:53:53 UTC 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Most of the uses of CbDataList appear to be abusing it for regular
list storage without any real need for CBDATA to be involved at all.

This replaces several of the simpler uses of CbDataList in favour of
std::list.

Amos
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (MingW32)

iQEcBAEBAgAGBQJUYMNwAAoJELJo5wb/XPRjXRoH/jsgFpxVeBauRRhH1Tw8rcQG
Y4dQrGPBRZu+OEI9WOyyy5iao0cc13ueSXoW6ppmjCcyEd162bKpvgDOvoCfb2NU
lsgwcxpEg0anSSPsA+TaNT7xnC6TB/z1MPMQZRHjzTrP8d9mo/usQdDPvgcEaEl5
hmUXcVrkY4TimkBjLfQnvIUUSEpgsT056PHYQa6vRLEZTPFnE0WlxdwoObV4N76m
fjcB7/vyBbuO0JLZOGiW1CABLpu5Cqx69fAtiRan8CIZr2mbNc/wROt9B23hqWg3
aC9sfozmuJUzPebinMyK/J1+EkAjLj/+Wx4FB/swIIVxrAbAnt3hSHdC059NNyU=
=8Zfg
-----END PGP SIGNATURE-----
-------------- next part --------------
=== modified file 'src/Notes.h'
--- src/Notes.h	2014-11-02 05:51:22 +0000
+++ src/Notes.h	2014-11-03 10:03:43 +0000
@@ -1,33 +1,32 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_NOTES_H
 #define SQUID_NOTES_H
 
 #include "acl/forward.h"
-#include "base/CbDataList.h"
 #include "base/RefCount.h"
 #include "format/Format.h"
 #include "MemPool.h"
 #include "SquidString.h"
 #include "typedefs.h"
 
 #include <string>
 #include <vector>
 
 class HttpRequest;
 class HttpReply;
 typedef RefCount<AccessLogEntry> AccessLogEntryPointer;
 
 /**
  * Used to store a note configuration. The notes are custom key:value
  * pairs ICAP request headers or ECAP options used to pass
  * custom transaction-state related meta information to squid
  * internal subsystems or to adaptation services.
  */
 class Note: public RefCountable

=== modified file 'src/acl/AtStepData.h'
--- src/acl/AtStepData.h	2014-11-02 05:51:22 +0000
+++ src/acl/AtStepData.h	2014-11-03 03:54:25 +0000
@@ -1,41 +1,40 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_ACLATSTEPDATA_H
 #define SQUID_ACLATSTEPDATA_H
 
 #if USE_OPENSSL
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "ssl/support.h"
 
 #include <list>
 
 class ACLAtStepData : public ACLData<Ssl::BumpStep>
 {
     MEMPROXY_CLASS(ACLAtStepData);
 
 public:
     ACLAtStepData();
     ACLAtStepData(ACLAtStepData const &);
     ACLAtStepData &operator= (ACLAtStepData const &);
     virtual ~ACLAtStepData();
     bool match(Ssl::BumpStep);
     virtual SBufList dump() const;
     void parse();
     bool empty() const;
-    virtual  ACLAtStepData *clone() const;
+    virtual ACLAtStepData *clone() const;
 
     std::list<Ssl::BumpStep> values;
 };
 
 #endif /* USE_OPENSSL */
 
 #endif /* SQUID_ACLSSL_ERRORDATA_H */

=== modified file 'src/acl/HierCodeData.h'
--- src/acl/HierCodeData.h	2014-11-02 05:51:22 +0000
+++ src/acl/HierCodeData.h	2014-11-03 03:53:44 +0000
@@ -1,37 +1,35 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_ACLHIERCODEDATA_H
 #define SQUID_ACLHIERCODEDATA_H
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "hier_code.h"
 
-/// \ingroup ACLAPI
 class ACLHierCodeData : public ACLData<hier_code>
 {
     MEMPROXY_CLASS(ACLHierCodeData);
 
 public:
     ACLHierCodeData();
     ACLHierCodeData(ACLHierCodeData const &);
     ACLHierCodeData &operator= (ACLHierCodeData const &);
     virtual ~ACLHierCodeData();
     bool match(hier_code);
     virtual SBufList dump() const;
     void parse();
     bool empty() const;
     virtual ACLData<hier_code> *clone() const;
 
-    // mask of codes this ACL might match.
+    /// mask of codes this ACL might match.
     bool values[HIER_MAX];
 };
 
 #endif /* SQUID_ACLHIERCODEDATA_H */

=== modified file 'src/acl/IntRange.cc'
--- src/acl/IntRange.cc	2014-09-13 13:59:43 +0000
+++ src/acl/IntRange.cc	2014-11-02 14:37:03 +0000
@@ -1,110 +1,98 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 /* DEBUG: section 28    Access Control */
 
 #include "squid.h"
 #include "acl/IntRange.h"
 #include "cache_cf.h"
 #include "Debug.h"
 #include "Parsing.h"
 
-/* explicit instantiation required for some systems */
-/** \cond AUTODOCS_IGNORE */
-template cbdata_type CbDataList< Range<int> >::CBDATA_CbDataList;
-/** \endcond */
-
 void
 ACLIntRange::parse()
 {
     char *a;
 
     while ((a = strtokFile())) {
         char *b = strchr(a, '-');
         unsigned short port1, port2;
 
         if (b) {
             *b = '\0';
             ++b;
         }
 
         port1 = xatos(a);
 
         if (b)
             port2 = xatos(b);
         else
             port2 = port1;
 
         if (port2 >= port1) {
-            RangeType temp (0,0);
-            temp.start = port1;
-            temp.end = port2+1;
+            RangeType temp(port1, port2+1);
             ranges.push_back(temp);
         } else {
             debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value");
             self_destruct();
         }
     }
 }
 
 bool
 ACLIntRange::empty() const
 {
     return ranges.empty();
 }
 
 bool
 ACLIntRange::match(int i)
 {
-    RangeType const toFind (i, i+1);
-    CbDataListIterator<RangeType> iter(ranges);
-
-    while (!iter.end()) {
-        const RangeType & element = iter.next();
-        RangeType result = element.intersection (toFind);
+    RangeType const toFind(i, i+1);
+    for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) {
+        const RangeType & element = *iter;
+        RangeType result = element.intersection(toFind);
 
         if (result.size())
             return true;
     }
 
     return false;
 }
 
 ACLData<int> *
 ACLIntRange::clone() const
 {
     if (!ranges.empty())
         fatal("ACLIntRange::clone: attempt to clone used ACL");
 
-    return new ACLIntRange (*this);
+    return new ACLIntRange(*this);
 }
 
 ACLIntRange::~ACLIntRange()
 {}
 
 SBufList
 ACLIntRange::dump() const
 {
     SBufList sl;
-    CbDataListIterator<RangeType> iter(ranges);
-
-    while (!iter.end()) {
+    for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) {
         SBuf sb;
-        const RangeType & element = iter.next();
+        const RangeType & element = *iter;
 
         if (element.size() == 1)
             sb.Printf("%d", element.start);
         else
             sb.Printf("%d-%d", element.start, element.end-1);
 
         sl.push_back(sb);
     }
 
     return sl;
 }
-

=== modified file 'src/acl/IntRange.h'
--- src/acl/IntRange.h	2014-11-02 05:51:22 +0000
+++ src/acl/IntRange.h	2014-11-03 03:47:47 +0000
@@ -1,35 +1,35 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_ACLINTRANGE_H
 #define SQUID_ACLINTRANGE_H
 
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "Range.h"
 
-/// \ingroup ACLAPI
+#include <list>
+
 class ACLIntRange : public ACLData<int>
 {
 
 public:
-    ACLIntRange() {};
+    ACLIntRange() {}
 
     virtual ~ACLIntRange();
     virtual bool match(int);
     virtual SBufList dump() const;
     virtual void parse();
     virtual bool empty() const;
     virtual ACLData<int> *clone() const;
 
 private:
     typedef Range<int> RangeType;
-    CbDataListContainer <RangeType> ranges;
+    std::list<RangeType> ranges;
 };
 
 #endif /* SQUID_ACLINTRANGE_H */

=== modified file 'src/acl/MethodData.cc'
--- src/acl/MethodData.cc	2014-09-13 13:59:43 +0000
+++ src/acl/MethodData.cc	2014-11-02 15:12:19 +0000
@@ -1,87 +1,69 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 /* DEBUG: section 28    Access Control */
 
 #include "squid.h"
 #include "acl/Checklist.h"
 #include "acl/MethodData.h"
 #include "cache_cf.h"
 #include "HttpRequestMethod.h"
 
 int ACLMethodData::ThePurgeCount = 0;
 
-ACLMethodData::ACLMethodData() : values (NULL)
-{}
-
-ACLMethodData::ACLMethodData(ACLMethodData const &old) : values (NULL)
+ACLMethodData::ACLMethodData(ACLMethodData const &old)
 {
-    assert (!old.values);
+    assert(old.values.empty());
 }
 
 ACLMethodData::~ACLMethodData()
 {
-    if (values)
-        delete values;
+    values.clear();
 }
 
-/// todo make this a pass-by-reference now that HTTPRequestMethods a full class?
 bool
 ACLMethodData::match(HttpRequestMethod toFind)
 {
-    return values->findAndTune(toFind);
+    for (std::list<HttpRequestMethod>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
+        if (*itr == toFind) {
+            // tune the list for LRU ordering
+            values.erase(itr);
+            values.push_front(toFind);
+            return true;
+        }
+    }
+    return false;
 }
 
-/* explicit instantiation required for some systems */
-
-/// \cond AUTODOCS_IGNORE
-template cbdata_type CbDataList<HttpRequestMethod>::CBDATA_CbDataList;
-/// \endcond
-
 SBufList
 ACLMethodData::dump() const
 {
     SBufList sl;
-    CbDataList<HttpRequestMethod> *data = values;
-
-    while (data != NULL) {
-        sl.push_back(data->element.image());
-        data = data->next;
+    for (std::list<HttpRequestMethod>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
+        sl.push_back((*itr).image());
     }
 
     return sl;
 }
 
 void
 ACLMethodData::parse()
 {
-    CbDataList<HttpRequestMethod> **Tail;
-    char *t = NULL;
-
-    for (Tail = &values; *Tail; Tail = &((*Tail)->next));
-    while ((t = strtokFile())) {
-        CbDataList<HttpRequestMethod> *q = new CbDataList<HttpRequestMethod> (HttpRequestMethod(t, NULL));
-        if (q->element == Http::METHOD_PURGE)
+    while (char *t = strtokFile()) {
+        values.push_back(HttpRequestMethod(t, NULL));
+        if (values.back() == Http::METHOD_PURGE)
             ++ThePurgeCount; // configuration code wants to know
-        *(Tail) = q;
-        Tail = &q->next;
     }
 }
 
-bool
-ACLMethodData::empty() const
-{
-    return values == NULL;
-}
-
 ACLData<HttpRequestMethod> *
 ACLMethodData::clone() const
 {
-    assert (!values);
+    assert(!values.empty());
     return new ACLMethodData(*this);
 }

=== modified file 'src/acl/MethodData.h'
--- src/acl/MethodData.h	2014-11-02 05:51:22 +0000
+++ src/acl/MethodData.h	2014-11-02 15:12:33 +0000
@@ -1,37 +1,38 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_ACLMETHODDATA_H
 #define SQUID_ACLMETHODDATA_H
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "base/CbDataList.h"
 #include "HttpRequestMethod.h"
 
+#include <list>
+
 class ACLMethodData : public ACLData<HttpRequestMethod>
 {
     MEMPROXY_CLASS(ACLMethodData);
 
 public:
-    ACLMethodData();
+    ACLMethodData() {}
     ACLMethodData(ACLMethodData const &);
     ACLMethodData &operator= (ACLMethodData const &);
     virtual ~ACLMethodData();
     bool match(HttpRequestMethod);
     virtual SBufList dump() const;
     void parse();
-    bool empty() const;
+    bool empty() const {return values.empty();}
     virtual ACLData<HttpRequestMethod> *clone() const;
 
-    CbDataList<HttpRequestMethod> *values;
+    std::list<HttpRequestMethod> values;
 
     static int ThePurgeCount; ///< PURGE methods seen by parse()
 };
 
 #endif /* SQUID_ACLMETHODDATA_H */

=== modified file 'src/acl/ProtocolData.cc'
--- src/acl/ProtocolData.cc	2014-09-13 13:59:43 +0000
+++ src/acl/ProtocolData.cc	2014-11-03 03:56:21 +0000
@@ -1,94 +1,77 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 /* DEBUG: section 28    Access Control */
 
 #include "squid.h"
 #include "acl/Checklist.h"
 #include "acl/ProtocolData.h"
 #include "cache_cf.h"
 #include "Debug.h"
 #include "wordlist.h"
 
-ACLProtocolData::ACLProtocolData() : values (NULL)
-{}
-
-ACLProtocolData::ACLProtocolData(ACLProtocolData const &old) : values (NULL)
+ACLProtocolData::ACLProtocolData(ACLProtocolData const &old)
 {
-    assert (!old.values);
+    assert(old.values.empty());
 }
 
 ACLProtocolData::~ACLProtocolData()
 {
-    if (values)
-        delete values;
+    values.clear();
 }
 
 bool
 ACLProtocolData::match(AnyP::ProtocolType toFind)
 {
-    return values->findAndTune (toFind);
+    for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
+        if (*itr == toFind) {
+            // tune the list for LRU ordering
+            values.erase(itr);
+            values.push_front(toFind);
+            return true;
+        }
+    }
+    return false;
 }
 
-/* explicit instantiation required for some systems */
-
-/// \cond AUTODOCS_IGNORE
-template cbdata_type CbDataList<AnyP::ProtocolType>::CBDATA_CbDataList;
-/// \endcond
-
 SBufList
 ACLProtocolData::dump() const
 {
     SBufList sl;
-    CbDataList<AnyP::ProtocolType> *data = values;
-
-    while (data != NULL) {
-        sl.push_back(SBuf(AnyP::ProtocolType_str[data->element]));
-        data = data->next;
+    for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
+        sl.push_back(SBuf(AnyP::ProtocolType_str[*itr]));
     }
 
     return sl;
 }
 
 void
 ACLProtocolData::parse()
 {
-    CbDataList<AnyP::ProtocolType> **Tail;
-    char *t = NULL;
-
-    for (Tail = &values; *Tail; Tail = &((*Tail)->next));
-    while ((t = strtokFile())) {
+    while (char *t = strtokFile()) {
         int p = AnyP::PROTO_NONE;
         for (; p < AnyP::PROTO_UNKNOWN; ++p) {
             if (strcasecmp(t, AnyP::ProtocolType_str[p]) == 0) {
-                CbDataList<AnyP::ProtocolType> *q = new CbDataList<AnyP::ProtocolType>(static_cast<AnyP::ProtocolType>(p));
-                *(Tail) = q;
-                Tail = &q->next;
+                values.push_back(static_cast<AnyP::ProtocolType>(p));
                 break;
             }
         }
         if (p == AnyP::PROTO_UNKNOWN) {
             debugs(28, DBG_IMPORTANT, "WARNING: Ignoring unknown protocol '" << t << "' in the ACL named '" << AclMatchedName << "'");
             // XXX: store the text pattern of this protocol name for live comparisons
         }
     }
 }
 
-bool
-ACLProtocolData::empty() const
-{
-    return values == NULL;
-}
-
 ACLData<AnyP::ProtocolType> *
 ACLProtocolData::clone() const
 {
     /* Splay trees don't clone yet. */
-    assert (!values);
+    assert(values.empty());
     return new ACLProtocolData(*this);
 }

=== modified file 'src/acl/ProtocolData.h'
--- src/acl/ProtocolData.h	2014-11-02 05:51:22 +0000
+++ src/acl/ProtocolData.h	2014-11-03 03:57:28 +0000
@@ -1,35 +1,36 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_ACLPROTOCOLDATA_H
 #define SQUID_ACLPROTOCOLDATA_H
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
 #include "anyp/ProtocolType.h"
-#include "base/CbDataList.h"
+
+#include <list>
 
 class ACLProtocolData : public ACLData<AnyP::ProtocolType>
 {
     MEMPROXY_CLASS(ACLProtocolData);
 
 public:
-    ACLProtocolData();
+    ACLProtocolData() {}
     ACLProtocolData(ACLProtocolData const &);
     ACLProtocolData &operator= (ACLProtocolData const &);
     virtual ~ACLProtocolData();
     bool match(AnyP::ProtocolType);
     virtual SBufList dump() const;
     void parse();
-    bool empty() const;
+    bool empty() const {return values.empty();}
     virtual ACLData<AnyP::ProtocolType> *clone() const;
 
-    CbDataList<AnyP::ProtocolType> *values;
+    std::list<AnyP::ProtocolType> values;
 };
 
 #endif /* SQUID_ACLPROTOCOLDATA_H */

=== modified file 'src/auth/QueueNode.h'
--- src/auth/QueueNode.h	2014-10-20 06:58:59 +0000
+++ src/auth/QueueNode.h	2014-11-03 10:38:43 +0000
@@ -1,31 +1,33 @@
 /*
  * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
  * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
 #ifndef SQUID_SRC_AUTH_QUEUENODE_H
 #define SQUID_SRC_AUTH_QUEUENODE_H
 
+#include "cbdata.h"
+
 namespace Auth
 {
 
 /**
  * A queue of auth requests waiting for verification to occur.
  *
  * Certain authentication schemes such a Basic and Bearer auth
  * permit credentials tokens to be repeated from multiple sources
  * simultaneously. This queue node allows multiple validation
  * queries to be collapsed into one backend helper lookup.
  * CBDATA and handlers stored in these queue nodes can be notified
  * all at once with a result when the lookup completes.
  */
 class QueueNode
 {
     MEMPROXY_CLASS(Auth::QueueNode);
 
 private:
     // we store CBDATA here, copy is not safe
     QueueNode(const QueueNode &);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CbDataList_removal_mk1.patch.sig
Type: application/octet-stream
Size: 287 bytes
Desc: not available
URL: <http://lists.squid-cache.org/pipermail/squid-dev/attachments/20141111/a2cb43ec/attachment-0001.obj>


More information about the squid-dev mailing list