From: Francesco Chemolli Date: Mon, 12 Jan 2015 21:22:00 +0000 (+0100) Subject: Ported ACLStringData from Splay to std::set X-Git-Tag: merge-candidate-3-v1~345^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56a821c4eef1e72a27228148c9d935b5d817bb11;p=thirdparty%2Fsquid.git Ported ACLStringData from Splay to std::set --- diff --git a/src/acl/StringData.cc b/src/acl/StringData.cc index f5cac0be7b..7b630c1dbc 100644 --- a/src/acl/StringData.cc +++ b/src/acl/StringData.cc @@ -14,94 +14,64 @@ #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 -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(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 *t; while ((t = strtokFile())) - values->insert(xstrdup(t), splaystrcmp); + stringValues.insert(SBuf(t)); } bool ACLStringData::empty() const { - return values->empty(); + return stringValues.empty(); } ACLData * ACLStringData::clone() const { /* Splay trees don't clone yet. */ - assert (!values); return new ACLStringData(*this); } diff --git a/src/acl/StringData.h b/src/acl/StringData.h index e041064b00..7989c56f51 100644 --- a/src/acl/StringData.h +++ b/src/acl/StringData.h @@ -11,7 +11,9 @@ #include "acl/Acl.h" #include "acl/Data.h" -#include "splay.h" +#include "SBuf.h" + +#include class ACLStringData : public ACLData { @@ -30,7 +32,9 @@ public: /// Insert a string data value void insert(const char *); - Splay *values; +private: + typedef std::set StringValues_t; + StringValues_t stringValues; }; #endif /* SQUID_ACLSTRINGDATA_H */