From: Amos Jeffries Date: Thu, 20 Nov 2014 09:34:09 +0000 (-0800) Subject: Cleanup: repalce several CbDataLIst uses with std::list X-Git-Tag: merge-candidate-3-v1~482 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd44274bf1149d9d5d0887a5ee9f05f7755445ce;p=thirdparty%2Fsquid.git Cleanup: repalce several CbDataLIst uses with std::list 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. Also includes some documentation and syntax polishing cleanup. --- diff --git a/src/Notes.h b/src/Notes.h index 15cf288e7d..6f17e0f334 100644 --- a/src/Notes.h +++ b/src/Notes.h @@ -10,7 +10,6 @@ #define SQUID_NOTES_H #include "acl/forward.h" -#include "base/CbDataList.h" #include "base/RefCount.h" #include "format/Format.h" #include "MemPool.h" diff --git a/src/acl/AtStepData.h b/src/acl/AtStepData.h index 459aa9e952..bd735061f1 100644 --- a/src/acl/AtStepData.h +++ b/src/acl/AtStepData.h @@ -13,7 +13,6 @@ #include "acl/Acl.h" #include "acl/Data.h" -#include "base/CbDataList.h" #include "ssl/support.h" #include @@ -31,7 +30,7 @@ public: virtual SBufList dump() const; void parse(); bool empty() const; - virtual ACLAtStepData *clone() const; + virtual ACLAtStepData *clone() const; std::list values; }; diff --git a/src/acl/HierCodeData.h b/src/acl/HierCodeData.h index 5cf25ab253..00d8d358d3 100644 --- a/src/acl/HierCodeData.h +++ b/src/acl/HierCodeData.h @@ -11,10 +11,8 @@ #include "acl/Acl.h" #include "acl/Data.h" -#include "base/CbDataList.h" #include "hier_code.h" -/// \ingroup ACLAPI class ACLHierCodeData : public ACLData { MEMPROXY_CLASS(ACLHierCodeData); @@ -30,7 +28,7 @@ public: bool empty() const; virtual ACLData *clone() const; - // mask of codes this ACL might match. + /// mask of codes this ACL might match. bool values[HIER_MAX]; }; diff --git a/src/acl/IntRange.cc b/src/acl/IntRange.cc index fb148298a0..d4dadff9e3 100644 --- a/src/acl/IntRange.cc +++ b/src/acl/IntRange.cc @@ -14,11 +14,6 @@ #include "Debug.h" #include "Parsing.h" -/* explicit instantiation required for some systems */ -/** \cond AUTODOCS_IGNORE */ -template cbdata_type CbDataList< Range >::CBDATA_CbDataList; -/** \endcond */ - void ACLIntRange::parse() { @@ -41,9 +36,7 @@ ACLIntRange::parse() 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"); @@ -61,12 +54,10 @@ ACLIntRange::empty() const bool ACLIntRange::match(int i) { - RangeType const toFind (i, i+1); - CbDataListIterator iter(ranges); - - while (!iter.end()) { - const RangeType & element = iter.next(); - RangeType result = element.intersection (toFind); + RangeType const toFind(i, i+1); + for (std::list::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) { + const RangeType & element = *iter; + RangeType result = element.intersection(toFind); if (result.size()) return true; @@ -81,7 +72,7 @@ ACLIntRange::clone() const if (!ranges.empty()) fatal("ACLIntRange::clone: attempt to clone used ACL"); - return new ACLIntRange (*this); + return new ACLIntRange(*this); } ACLIntRange::~ACLIntRange() @@ -91,11 +82,9 @@ SBufList ACLIntRange::dump() const { SBufList sl; - CbDataListIterator iter(ranges); - - while (!iter.end()) { + for (std::list::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); @@ -107,4 +96,3 @@ ACLIntRange::dump() const return sl; } - diff --git a/src/acl/IntRange.h b/src/acl/IntRange.h index df9605a116..bca4acffac 100644 --- a/src/acl/IntRange.h +++ b/src/acl/IntRange.h @@ -10,15 +10,15 @@ #define SQUID_ACLINTRANGE_H #include "acl/Data.h" -#include "base/CbDataList.h" #include "Range.h" -/// \ingroup ACLAPI +#include + class ACLIntRange : public ACLData { public: - ACLIntRange() {}; + ACLIntRange() {} virtual ~ACLIntRange(); virtual bool match(int); @@ -29,7 +29,7 @@ public: private: typedef Range RangeType; - CbDataListContainer ranges; + std::list ranges; }; #endif /* SQUID_ACLINTRANGE_H */ diff --git a/src/acl/MethodData.cc b/src/acl/MethodData.cc index 16cd9c8757..17086a08bc 100644 --- a/src/acl/MethodData.cc +++ b/src/acl/MethodData.cc @@ -16,42 +16,36 @@ 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::const_iterator i = values.begin(); i != values.end(); ++i) { + if (*i == toFind) { + // tune the list for LRU ordering + values.erase(i); + values.push_front(toFind); + return true; + } + } + return false; } -/* explicit instantiation required for some systems */ - -/// \cond AUTODOCS_IGNORE -template cbdata_type CbDataList::CBDATA_CbDataList; -/// \endcond - SBufList ACLMethodData::dump() const { SBufList sl; - CbDataList *data = values; - - while (data != NULL) { - sl.push_back(data->element.image()); - data = data->next; + for (std::list::const_iterator i = values.begin(); i != values.end(); ++i) { + sl.push_back((*i).image()); } return sl; @@ -60,30 +54,18 @@ ACLMethodData::dump() const void ACLMethodData::parse() { - CbDataList **Tail; - char *t = NULL; - - for (Tail = &values; *Tail; Tail = &((*Tail)->next)); - while ((t = strtokFile())) { + while (char *t = strtokFile()) { HttpRequestMethod m; m.HttpRequestMethodXXX(t); - CbDataList *q = new CbDataList(m); - if (q->element == Http::METHOD_PURGE) + values.push_back(m); + 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 * ACLMethodData::clone() const { - assert (!values); + assert(values.empty()); return new ACLMethodData(*this); } diff --git a/src/acl/MethodData.h b/src/acl/MethodData.h index a3c02dcafb..bca112e918 100644 --- a/src/acl/MethodData.h +++ b/src/acl/MethodData.h @@ -11,25 +11,26 @@ #include "acl/Acl.h" #include "acl/Data.h" -#include "base/CbDataList.h" #include "http/RequestMethod.h" +#include + class ACLMethodData : public ACLData { 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 *clone() const; - CbDataList *values; + std::list values; static int ThePurgeCount; ///< PURGE methods seen by parse() }; diff --git a/src/acl/ProtocolData.cc b/src/acl/ProtocolData.cc index 388b2c102e..6f8080e36a 100644 --- a/src/acl/ProtocolData.cc +++ b/src/acl/ProtocolData.cc @@ -15,41 +15,36 @@ #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::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::CBDATA_CbDataList; -/// \endcond - SBufList ACLProtocolData::dump() const { SBufList sl; - CbDataList *data = values; - - while (data != NULL) { - sl.push_back(SBuf(AnyP::ProtocolType_str[data->element])); - data = data->next; + for (std::list::const_iterator itr = values.begin(); itr != values.end(); ++itr) { + sl.push_back(SBuf(AnyP::ProtocolType_str[*itr])); } return sl; @@ -58,17 +53,11 @@ ACLProtocolData::dump() const void ACLProtocolData::parse() { - CbDataList **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 *q = new CbDataList(static_cast(p)); - *(Tail) = q; - Tail = &q->next; + values.push_back(static_cast(p)); break; } } @@ -79,16 +68,10 @@ ACLProtocolData::parse() } } -bool -ACLProtocolData::empty() const -{ - return values == NULL; -} - ACLData * ACLProtocolData::clone() const { /* Splay trees don't clone yet. */ - assert (!values); + assert(values.empty()); return new ACLProtocolData(*this); } diff --git a/src/acl/ProtocolData.h b/src/acl/ProtocolData.h index 05d054cf6e..90f2639403 100644 --- a/src/acl/ProtocolData.h +++ b/src/acl/ProtocolData.h @@ -12,24 +12,25 @@ #include "acl/Acl.h" #include "acl/Data.h" #include "anyp/ProtocolType.h" -#include "base/CbDataList.h" + +#include class ACLProtocolData : public ACLData { 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 *clone() const; - CbDataList *values; + std::list values; }; #endif /* SQUID_ACLPROTOCOLDATA_H */ diff --git a/src/auth/QueueNode.h b/src/auth/QueueNode.h index 5854b120b3..1f52e0545d 100644 --- a/src/auth/QueueNode.h +++ b/src/auth/QueueNode.h @@ -9,6 +9,8 @@ #ifndef SQUID_SRC_AUTH_QUEUENODE_H #define SQUID_SRC_AUTH_QUEUENODE_H +#include "cbdata.h" + namespace Auth {