]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/acl/StringData.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / acl / StringData.cc
index 7775b7cfd9069ed423229465d2572fd229e0d729..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)
+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)
+ACLStringData::match(const SBuf &tf)
 {
-    if (!values || !toFind)
+    if (stringValues.empty() || tf.isEmpty())
         return 0;
 
-    debugs(28, 3, "aclMatchStringList: checking '" << toFind << "'");
+    debugs(28, 3, "aclMatchStringList: checking '" << tf << "'");
 
-    char * const * result = values->find(const_cast<char *>(toFind), splaystrcmp);
+    bool found = (stringValues.find(tf) != stringValues.end());
+    debugs(28, 3, "aclMatchStringList: '" << tf << "' " << (found ? "found" : "NOT found"));
 
-    debugs(28, 3, "aclMatchStringList: '" << toFind << "' " << (result ? "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));
-    }
-};
+// XXX: performance regression due to SBuf(char*) data-copies.
+bool
+ACLStringData::match(char const *toFind)
+{
+    return match(SBuf(toFind));
+}
 
 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()
 {
-    char *t;
-
-    while ((t = strtokFile()))
-        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);
 }