]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed Acl::StringData
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 22:27:34 +0000 (23:27 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 22:27:34 +0000 (23:27 +0100)
src/acl/StringData.cc
src/acl/StringData.h

index f6a43117de79be1bb93b4524223e1824222e38f9..778f951aadc919f2832bf2e2354b13fe277f02d2 100644 (file)
@@ -44,7 +44,7 @@ splaystrcmp (char * const &l, char * const &r)
 void
 ACLStringData::insert(const char *value)
 {
-    values = values->insert(xstrdup(value), splaystrcmp);
+    values->insert(xstrdup(value), splaystrcmp);
 }
 
 bool
@@ -55,30 +55,27 @@ ACLStringData::match(char const *toFind)
 
     debugs(28, 3, "aclMatchStringList: checking '" << toFind << "'");
 
-    values = values->splay((char *)toFind, splaystrcmp);
+    char * const * result = values->find(const_cast<char *>(toFind), splaystrcmp);
 
-    debugs(28, 3, "aclMatchStringList: '" << toFind << "' " << (splayLastResult ? "NOT found" : "found"));
+    debugs(28, 3, "aclMatchStringList: '" << toFind << "' " << (result ? "found" : "NOT found"));
 
-    return !splayLastResult;
+    return (result != NULL);
 }
 
-static void
-aclDumpStringWalkee(char * const & node_data, void *outlist)
-{
-    /* outlist is really a SBufList* */
-    static_cast<SBufList*>(outlist)->push_back(SBuf(node_data));
-}
+// visitor functor to collect the contents of the Arp Acl
+struct StringDataAclDumpVisitor {
+    SBufList contents;
+    void operator() (char * const& node_data) {
+        contents.push_back(SBuf(node_data));
+    }
+};
 
 SBufList
 ACLStringData::dump() const
 {
-    SBufList sl;
-    /* damn this is VERY inefficient for long ACL lists... filling
-     * a SBufList this way costs Sum(1,N) iterations. For instance
-     * a 1000-elements list will be filled in 499500 iterations.
-     */
-    values->walk(aclDumpStringWalkee, &sl);
-    return sl;
+    StringDataAclDumpVisitor visitor;
+    values->visit(visitor);
+    return visitor.contents;
 }
 
 void
@@ -87,7 +84,7 @@ ACLStringData::parse()
     char *t;
 
     while ((t = strtokFile()))
-        values = values->insert(xstrdup(t), splaystrcmp);
+        values->insert(xstrdup(t), splaystrcmp);
 }
 
 bool
index e0dcedceeb1b3eafca82e78d1a5f5bb2a3287dd5..e041064b0012816b9274b43c77622a57110d56d6 100644 (file)
@@ -30,7 +30,7 @@ public:
     /// Insert a string data value
     void insert(const char *);
 
-    SplayNode<char *> *values;
+    Splay<char *> *values;
 };
 
 #endif /* SQUID_ACLSTRINGDATA_H */