]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/acl/StringData.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / acl / StringData.cc
index f6a43117de79be1bb93b4524223e1824222e38f9..3bec669a2ca770d00b448c8da4cb0d93150bfc3a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
 #include "squid.h"
 #include "acl/Checklist.h"
 #include "acl/StringData.h"
-#include "cache_cf.h"
+#include "ConfigParser.h"
 #include "Debug.h"
 
-ACLStringData::ACLStringData() : values (NULL)
-{}
-
-ACLStringData::ACLStringData(ACLStringData const &old) : values (NULL)
-{
-    assert (!old.values);
-}
-
-template<class T>
-inline void
-xRefFree(T &thing)
+ACLStringData::ACLStringData(ACLStringData const &old) : stringValues(old.stringValues)
 {
-    xfree (thing);
-}
-
-ACLStringData::~ACLStringData()
-{
-    if (values)
-        values->destroy(xRefFree);
-}
-
-static int
-splaystrcmp (char * const &l, char * const &r)
-{
-    return strcmp (l,r);
 }
 
 void
 ACLStringData::insert(const char *value)
 {
-    values = values->insert(xstrdup(value), splaystrcmp);
+    stringValues.insert(SBuf(value));
 }
 
 bool
-ACLStringData::match(char const *toFind)
+ACLStringData::match(const SBuf &tf)
 {
-    if (!values || !toFind)
+    if (stringValues.empty() || tf.isEmpty())
         return 0;
 
-    debugs(28, 3, "aclMatchStringList: checking '" << toFind << "'");
-
-    values = values->splay((char *)toFind, splaystrcmp);
+    debugs(28, 3, "aclMatchStringList: checking '" << tf << "'");
 
-    debugs(28, 3, "aclMatchStringList: '" << toFind << "' " << (splayLastResult ? "NOT found" : "found"));
+    bool found = (stringValues.find(tf) != stringValues.end());
+    debugs(28, 3, "aclMatchStringList: '" << tf << "' " << (found ? "found" : "NOT found"));
 
-    return !splayLastResult;
+    return found;
 }
 
-static void
-aclDumpStringWalkee(char * const & node_data, void *outlist)
+// XXX: performance regression due to SBuf(char*) data-copies.
+bool
+ACLStringData::match(char const *toFind)
 {
-    /* outlist is really a SBufList* */
-    static_cast<SBufList*>(outlist)->push_back(SBuf(node_data));
+    return match(SBuf(toFind));
 }
 
 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);
+    sl.insert(sl.end(), stringValues.begin(), stringValues.end());
     return sl;
 }
 
 void
 ACLStringData::parse()
 {
-    char *t;
-
-    while ((t = strtokFile()))
-        values = values->insert(xstrdup(t), splaystrcmp);
+    while (const char *t = ConfigParser::strtokFile())
+        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);
 }