]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Migrated acl/DomainData to Splay
authorFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 16:05:48 +0000 (17:05 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Tue, 30 Dec 2014 16:05:48 +0000 (17:05 +0100)
include/splay.h
src/acl/DomainData.cc
src/acl/DomainData.h

index aa3e1c2b2513e371b0e16522e544a90dbfbe05e3..42475d4dc3c04dc131bcaa630248914fc5e0cf51 100644 (file)
@@ -85,7 +85,7 @@ public:
 
     size_t size() const;
 
-    bool empty() { return size() == 0; }
+    bool empty() const { return size() == 0; }
 
     const_iterator begin() const;
 
index 6f37d80f0f828a8e099d4581b71192f8787f9fe0..13b23d3df01e73d57acfe2f05116422115b46a80 100644 (file)
@@ -106,30 +106,27 @@ ACLDomainData::match(char const *host)
 
     debugs(28, 3, "aclMatchDomainList: checking '" << host << "'");
 
-    domains = domains->splay((char *)host, aclHostDomainCompare);
+    char *h = const_cast<char *>(host);
+    char const * const * result = domains->find(h, aclHostDomainCompare);
 
-    debugs(28, 3, "aclMatchDomainList: '" << host << "' " << (splayLastResult ? "NOT found" : "found"));
+    debugs(28, 3, "aclMatchDomainList: '" << host << "' " << (result ? "found" : "NOT found"));
 
-    return !splayLastResult;
+    return (result != NULL);
 }
 
-static void
-aclDumpDomainListWalkee(char * const & node_data, void *outlist)
-{
-    /* outlist is really a SBufList ** */
-    static_cast<SBufList *>(outlist)->push_back(SBuf(node_data));
-}
+struct AclDomainDataDumpVisitor {
+    SBufList contents;
+    void operator() (char * const & node_data) {
+        contents.push_back(SBuf(node_data));
+    }
+};
 
 SBufList
 ACLDomainData::dump() const
 {
-    SBufList sl;
-    /* damn this is VERY inefficient for long ACL lists... filling
-     * a wordlist this way costs Sum(1,N) iterations. For instance
-     * a 1000-elements list will be filled in 499500 iterations.
-     */
-    domains->walk(aclDumpDomainListWalkee, &sl);
-    return sl;
+    AclDomainDataDumpVisitor visitor;
+    domains->visit(visitor);
+    return visitor.contents;
 }
 
 void
@@ -137,9 +134,12 @@ ACLDomainData::parse()
 {
     char *t = NULL;
 
+    if (!domains)
+        domains = new Splay<char *>();
+
     while ((t = strtokFile())) {
         Tolower(t);
-        domains = domains->insert(xstrdup(t), aclDomainCompare);
+        domains->insert(xstrdup(t), aclDomainCompare);
     }
 }
 
index 7792e7eef2f142d8ffde4f35573870d500c1c089..4115eb38c819a10838761e60fa5713d3859e7dbb 100644 (file)
@@ -25,7 +25,7 @@ public:
     bool empty() const;
     virtual ACLData<char const *> *clone() const;
 
-    SplayNode<char *> *domains;
+    Splay<char *> *domains;
 };
 
 #endif /* SQUID_ACLDOMAINDATA_H */