]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Ported ACLStringData from Splay to std::set<SBuf>
authorFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 12 Jan 2015 21:22:00 +0000 (22:22 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Mon, 12 Jan 2015 21:22:00 +0000 (22:22 +0100)
src/acl/StringData.cc
src/acl/StringData.h

index f5cac0be7b31ef88576459f848f2d8944b2245e3..7b630c1dbc24d10fce4bd84c6502ee47ac407936 100644 (file)
 #include "cache_cf.h"
 #include "Debug.h"
 
-ACLStringData::ACLStringData() : values (NULL)
+ACLStringData::ACLStringData()
 {}
 
-ACLStringData::ACLStringData(ACLStringData const &old) : values (NULL)
+ACLStringData::ACLStringData(ACLStringData const &old) : stringValues(old.stringValues)
 {
-    assert (!old.values);
-}
-
-template<class T>
-inline void
-xRefFree(T &thing)
-{
-    xfree (thing);
 }
 
 ACLStringData::~ACLStringData()
 {
-    if (values) {
-        values->destroy(xRefFree);
-        delete values;
-    }
-}
-
-static int
-splaystrcmp (char * const &l, char * const &r)
-{
-    return strcmp (l,r);
 }
 
 void
 ACLStringData::insert(const char *value)
 {
-    values->insert(xstrdup(value), splaystrcmp);
+    stringValues.insert(SBuf(value));
 }
 
 bool
 ACLStringData::match(char const *toFind)
 {
-    if (!values || !toFind)
+    if (stringValues.empty() || !toFind)
         return 0;
 
-    debugs(28, 3, "aclMatchStringList: checking '" << toFind << "'");
-
-    char * const * result = values->find(const_cast<char *>(toFind), splaystrcmp);
+    SBuf tf(toFind);
+    debugs(28, 3, "aclMatchStringList: checking '" << tf << "'");
 
-    debugs(28, 3, "aclMatchStringList: '" << toFind << "' " << (result ? "found" : "NOT found"));
+    bool found = (stringValues.find(tf) != stringValues.end());
+    debugs(28, 3, "aclMatchStringList: '" << tf << "' " << (found ? "found" : "NOT found"));
 
-    return (result != NULL);
+    return found;
 }
 
-// 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
 {
-    StringDataAclDumpVisitor visitor;
-    values->visit(visitor);
-    return visitor.contents;
+    SBufList sl;
+    sl.insert(sl.end(), stringValues.begin(), stringValues.end());
+    return sl;
 }
 
 void
 ACLStringData::parse()
 {
-    if (!values)
-        values = new Splay<char *>();
-
     char *t;
     while ((t = strtokFile()))
-        values->insert(xstrdup(t), splaystrcmp);
+        stringValues.insert(SBuf(t));
 }
 
 bool
 ACLStringData::empty() const
 {
-    return values->empty();
+    return stringValues.empty();
 }
 
 ACLData<char const *> *
 ACLStringData::clone() const
 {
     /* Splay trees don't clone yet. */
-    assert (!values);
     return new ACLStringData(*this);
 }
 
index e041064b0012816b9274b43c77622a57110d56d6..7989c56f51670326b1f90110cda995a1f0de5178 100644 (file)
@@ -11,7 +11,9 @@
 
 #include "acl/Acl.h"
 #include "acl/Data.h"
-#include "splay.h"
+#include "SBuf.h"
+
+#include <set>
 
 class ACLStringData : public ACLData<char const *>
 {
@@ -30,7 +32,9 @@ public:
     /// Insert a string data value
     void insert(const char *);
 
-    Splay<char *> *values;
+private:
+    typedef std::set<SBuf> StringValues_t;
+    StringValues_t stringValues;
 };
 
 #endif /* SQUID_ACLSTRINGDATA_H */