]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Reverted buggy change on CharacterSet::operator+=, documentation touches
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 18 Dec 2013 15:22:06 +0000 (16:22 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 18 Dec 2013 15:22:06 +0000 (16:22 +0100)
src/base/CharacterSet.cc
src/base/CharacterSet.h

index 697276aed2445474ed5f460af807bc89aa3b3f58..cabe47b6f5223fc3dde3b3530ec7813915d9f689 100644 (file)
@@ -1,18 +1,18 @@
 #include "squid.h"
-
 #include "CharacterSet.h"
 
-#include <algorithm>
-
-static bool
-isNonZero(uint8_t i) {
-    return i!=0;
-}
-
 const CharacterSet &
 CharacterSet::operator +=(const CharacterSet &src)
 {
-    std::copy_if(src.chars_.begin(),src.chars_.end(),chars_.begin(),isNonZero);
+    Storage::const_iterator s = src.chars_.begin();
+    const Storage::const_iterator e = src.chars_.end();
+    Storage::iterator d = chars_.begin();
+    while (s != e) {
+        if (*s)
+            *d = 1;
+        ++s;
+        ++d;
+    }
     return *this;
 }
 
@@ -24,7 +24,7 @@ CharacterSet::add(const unsigned char c)
 }
 
 CharacterSet::CharacterSet(const char *label, const char * const c)
-: name(label == NULL ? "anonymous" : label), chars_(vector_type(256,0))
+: name(label == NULL ? "anonymous" : label), chars_(Storage(256,0))
 {
     const size_t clen = strlen(c);
     for (size_t i = 0; i < clen; ++i)
index 9b02c0cd87e691f6a64f3676c43945c5bc4d57ed..48a613e9c36b769d081c6b0bee1ca18bbb2ade41 100644 (file)
@@ -3,20 +3,20 @@
 
 #include <vector>
 
-/// Optimized set of C chars, with quick membership test and merge support
+/// optimized set of C chars, with quick membership test and merge support
 class CharacterSet
 {
 public:
-    typedef std::vector<uint8_t> vector_type;
+    typedef std::vector<uint8_t> Storage;
 
-    /// define a character set with the given label ("anonymous" if NULL,
+    /// define a character set with the given label ("anonymous" if NULL)
     ///  with specified initial contents
     CharacterSet(const char *label, const char * const initial);
 
     /// whether a given character exists in the set
-    bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)] == 1;}
+    bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)] != 0;}
 
-    /// add a given character to the character set.
+    /// add a given character to the character set
     CharacterSet & add(const unsigned char c);
 
     /// add all characters from the given CharacterSet to this one
@@ -26,13 +26,13 @@ public:
     const char * name;
 
 private:
-    /** characters present in this set.
+    /** index of characters in this set
      *
      * \note guaranteed to be always 256 slots big, as forced in the
      *  constructor. This assumption is relied upon in operator[], add,
      *  operator+=
      */
-   vector_type chars_;
+   Storage chars_;
 };
 
 #endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */