From e855eca140398a209d1cb1e95a237f2aad5c29a5 Mon Sep 17 00:00:00 2001 From: hno <> Date: Mon, 9 May 2005 05:31:06 +0000 Subject: [PATCH] Refactor ACLIntRange to use ListContainer rather than mucking around directly with List memers. If these lists grows large then ACLIntRange is a candidate for splay implementation. --- src/ACLIntRange.cc | 65 ++++++++++++++-------------------------------- src/ACLIntRange.h | 8 +++--- 2 files changed, 23 insertions(+), 50 deletions(-) diff --git a/src/ACLIntRange.cc b/src/ACLIntRange.cc index 4ff97466ba..ee8ac16988 100644 --- a/src/ACLIntRange.cc +++ b/src/ACLIntRange.cc @@ -1,5 +1,5 @@ /* - * $Id: ACLIntRange.cc,v 1.5 2005/05/08 09:15:39 serassio Exp $ + * $Id: ACLIntRange.cc,v 1.6 2005/05/08 23:31:06 hno Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Robert Collins @@ -45,15 +45,10 @@ template cbdata_type List > void ACLIntRange::parse() { - RangeType **Tail; - RangeType *q = NULL; char *t = NULL; - for (Tail = &ranges; *Tail; Tail = &((*Tail)->next)) - - ; while ((t = strtokFile())) { - Range temp (0,0); + RangeType temp (0,0); temp.start = atoi(t); t = strchr(t, '-'); @@ -62,47 +57,28 @@ ACLIntRange::parse() else temp.end = temp.start+1; - q = new RangeType (temp); - - *(Tail) = q; - - Tail = &q->next; + ranges.push_back(temp); } } bool ACLIntRange::empty() const { - return ranges == NULL; + return ranges.empty(); } bool ACLIntRange::match(int i) { - Range const toFind (i, i+1); - RangeType *prev; - RangeType *data = ranges; - prev = NULL; - - while (data) { - Range result = data->element.intersection (toFind); - - if (result.size()) { - /* matched */ + RangeType const toFind (i, i+1); + ListIterator iter(ranges); - if (prev != NULL) { - /* shift the element just found to the second position - * in the list */ - prev->next = data->next; - data->next = ranges->next; - ranges->next = data; - } + while (!iter.end()) { + const RangeType & element = iter.next(); + RangeType result = element.intersection (toFind); + if (result.size()) return true; - } - - prev = data; - data = data->next; } return false; @@ -111,34 +87,31 @@ ACLIntRange::match(int i) ACLData * ACLIntRange::clone() const { - if (ranges) + if (!ranges.empty()) fatal("ACLIntRange::clone: attempt to clone used ACL"); return new ACLIntRange (*this); } ACLIntRange::~ACLIntRange () -{ - if (ranges) - delete ranges; -} +{} wordlist * ACLIntRange::dump () { wordlist *W = NULL; char buf[32]; - RangeType *data = ranges; + ListIterator iter(ranges); - while (data != NULL) { - if (data->element.size() == 1) - snprintf(buf, sizeof(buf), "%d", data->element.start); + while (!iter.end()) { + const RangeType & element = iter.next(); + + if (element.size() == 1) + snprintf(buf, sizeof(buf), "%d", element.start); else - snprintf(buf, sizeof(buf), "%d-%d", data->element.start, data->element.end); + snprintf(buf, sizeof(buf), "%d-%d", element.start, element.end); wordlistAdd(&W, buf); - - data = data->next; } return W; diff --git a/src/ACLIntRange.h b/src/ACLIntRange.h index 9065006bed..ac04a2810d 100644 --- a/src/ACLIntRange.h +++ b/src/ACLIntRange.h @@ -1,6 +1,6 @@ /* - * $Id: ACLIntRange.h,v 1.3 2005/05/08 06:36:45 hno Exp $ + * $Id: ACLIntRange.h,v 1.4 2005/05/08 23:31:06 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -43,7 +43,7 @@ class ACLIntRange : public ACLData { public: - ACLIntRange() : ranges(NULL) {} + ACLIntRange() {}; virtual ~ACLIntRange(); virtual bool match(int); @@ -53,8 +53,8 @@ public: virtual ACLData *clone() const; private: - typedef List > RangeType; - RangeType *ranges; + typedef Range RangeType; + ListContainer ranges; }; #endif /* SQUID_ACLINTRANGE_H */ -- 2.47.3