]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Clarified comment in SBufAlgos.h, improved coding standards adherence
authorFrancesco Chemolli <kinkie@squid-cache.org>
Sat, 14 Dec 2013 15:58:04 +0000 (16:58 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Sat, 14 Dec 2013 15:58:04 +0000 (16:58 +0100)
src/SBufAlgos.h
src/SBufList.cc

index ae43c036824738d832f02e6d5e3e29135aafcbe1..8c34b075f3147918aa31838e57d71904b63c2780 100644 (file)
@@ -2,6 +2,7 @@
 #define SQUID_SBUFALGOS_H_
 
 #include "SBuf.h"
+
 #include <algorithm>
 #include <numeric>
 
@@ -37,12 +38,12 @@ class SBufAddLength
 {
 public:
     explicit SBufAddLength(const SBuf &separator) :
-        separator_len(separator.length()) {}
+        separatorLen_(separator.length()) {}
     SBuf::size_type operator()(const SBuf::size_type sz, const SBuf & item) {
-        return sz + item.length() + separator_len;
+        return sz + item.length() + separatorLen_;
     }
 private:
-    SBuf::size_type separator_len;
+    SBuf::size_type separatorLen_;
 };
 
 /// join all the SBuf in a container of SBuf into a single SBuf, separating with separator
@@ -53,7 +54,11 @@ SBufContainerJoin(const Container &items, const SBuf& separator)
     // optimization: pre-calculate needed storage
     const SBuf::size_type sz = std::accumulate(items.begin(), items.end(), 0, SBufAddLength(separator));
 
-    // protect against blindly dereferencing items.begin() if items.size()==0
+    // sz can be zero in two cases: either items is empty, or all items
+    //  are zero-length. In the former case, we must protect against
+    //  dereferencing the iterator later on, and checking sz is more efficient
+    //  than checking items.size(). This check also provides an optimization
+    //  for the latter case without adding complexity.
     if (sz == 0)
         return SBuf();
 
index 80827ae4238d90e1af1c50f4f9fcb2c8115d8d0c..f4025eeadf3af868d7084bda56ba722b2d4d6e12 100644 (file)
@@ -1,7 +1,6 @@
 #include "squid.h"
-#include "SBufList.h"
 #include "SBufAlgos.h"
-#include "wordlist.h"
+#include "SBufList.h"
 
 bool
 IsMember(const SBufList & sl, const SBuf &S, const SBufCaseSensitive case_sensitive)