From: Francesco Chemolli Date: Sat, 14 Dec 2013 15:58:04 +0000 (+0100) Subject: Clarified comment in SBufAlgos.h, improved coding standards adherence X-Git-Tag: SQUID_3_5_0_1~463^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d2e48819bc3f3ded580e9005f2f4b8c434a9b9c;p=thirdparty%2Fsquid.git Clarified comment in SBufAlgos.h, improved coding standards adherence --- diff --git a/src/SBufAlgos.h b/src/SBufAlgos.h index ae43c03682..8c34b075f3 100644 --- a/src/SBufAlgos.h +++ b/src/SBufAlgos.h @@ -2,6 +2,7 @@ #define SQUID_SBUFALGOS_H_ #include "SBuf.h" + #include #include @@ -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(); diff --git a/src/SBufList.cc b/src/SBufList.cc index 80827ae423..f4025eeadf 100644 --- a/src/SBufList.cc +++ b/src/SBufList.cc @@ -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)