]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Moved std::hash<SBuf> from SBuf.h to SBufAlgos.h
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 29 Jul 2015 13:27:15 +0000 (15:27 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 29 Jul 2015 13:27:15 +0000 (15:27 +0200)
src/Makefile.am
src/SBuf.cc
src/SBuf.h
src/SBufAlgos.cc [new file with mode: 0644]
src/SBufAlgos.h
src/tests/testSBuf.cc

index c1c9668cdadd418f728ed2632b88a91de6093400..6016ad7161421916f297d523dd4da2cbdfbc5d0f 100644 (file)
@@ -3498,6 +3498,8 @@ tests_testSBuf_SOURCES= \
        $(SBUF_SOURCE) \
        SBufDetailedStats.h \
        tests/stub_SBufDetailedStats.cc \
+       SBufAlgos.h \
+       SBufAlgos.cc \
        SBufStream.h \
        tests/stub_time.cc \
        tests/stub_debug.cc \
@@ -3535,6 +3537,7 @@ tests_testSBufList_SOURCES= \
        SBufList.h \
        SBufList.cc \
        SBufAlgos.h \
+       SBufAlgos.cc \
        SBufDetailedStats.h \
        tests/stub_SBufDetailedStats.cc \
        SBufStream.h \
index 27432bde1e00e23f70fb269ad3256a3f11fa691d..24b3ccdfb272bed65c86c176c804497a01893e41 100644 (file)
@@ -952,17 +952,3 @@ SBuf::cow(SBuf::size_type newsize)
     }
     reAlloc(newsize);
 }
-
-std::size_t std::hash<SBuf>::operator() (const SBuf & sbuf) const noexcept
-{
-    //ripped and adapted from hash_string
-    const char *s = sbuf.rawContent();
-    size_t rv = 0;
-    SBuf::size_type len=sbuf.length();
-    while (len != 0) {
-        rv ^= 271 * *s;
-        ++s;
-        --len;
-    }
-    return rv ^ (sbuf.length() * 271);
-}
index 5858a1ff0d2340706c18ed5f1dba275717d3f5c9..3cff0b4a4ab448394aa9dfda7bb60476007a15dc 100644 (file)
@@ -722,15 +722,6 @@ ToLower(SBuf buf)
     return buf;
 }
 
-namespace std {
-    /// default hash functor to support std::unordered_map<SBuf,*>
-    template <>
-    struct hash<SBuf>
-    {
-        size_t operator()(const SBuf &) const noexcept;
-    };
-}
-
 inline
 SBufIterator::SBufIterator(const SBuf &s, size_type pos)
     : iter(s.rawContent()+pos)
diff --git a/src/SBufAlgos.cc b/src/SBufAlgos.cc
new file mode 100644 (file)
index 0000000..68ddfeb
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "SBufAlgos.h"
+
+std::size_t std::hash<SBuf>::operator() (const SBuf & sbuf) const noexcept
+{
+    //ripped and adapted from hash_string
+    const char *s = sbuf.rawContent();
+    size_t rv = 0;
+    SBuf::size_type len=sbuf.length();
+    while (len != 0) {
+        rv ^= 271 * *s;
+        ++s;
+        --len;
+    }
+    return rv ^ (sbuf.length() * 271);
+}
index 213e8cc9ae315829f877457c9aab168178d36702..a9ea4208e56aeccebe4189ba6af231f3885958e4 100644 (file)
@@ -81,5 +81,14 @@ SBufContainerJoin(const Container &items, const SBuf& separator)
     return rv;
 }
 
+namespace std {
+    /// default hash functor to support std::unordered_map<SBuf,*>
+    template <>
+    struct hash<SBuf>
+    {
+        size_t operator()(const SBuf &) const noexcept;
+    };
+}
+
 #endif /* SQUID_SBUFALGOS_H_ */
 
index 25509cd9b4e660b9254348d8d871cc09ef46116b..a9207bc4ad3b264d81ea3d42506e77be5ef5e5ba 100644 (file)
@@ -10,6 +10,7 @@
 #include "base/CharacterSet.h"
 #include "SBuf.h"
 #include "SBufFindTest.h"
+#include "SBufAlgos.h"
 #include "SBufStream.h"
 #include "SquidString.h"
 #include "testSBuf.h"