From: Francesco Chemolli Date: Wed, 29 Jul 2015 13:27:15 +0000 (+0200) Subject: Moved std::hash from SBuf.h to SBufAlgos.h X-Git-Tag: merge-candidate-3-v1~24^2^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25436c304645b476a8faa711ddd9dc7e382b64fe;p=thirdparty%2Fsquid.git Moved std::hash from SBuf.h to SBufAlgos.h --- diff --git a/src/Makefile.am b/src/Makefile.am index c1c9668cda..6016ad7161 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/SBuf.cc b/src/SBuf.cc index 27432bde1e..24b3ccdfb2 100644 --- a/src/SBuf.cc +++ b/src/SBuf.cc @@ -952,17 +952,3 @@ SBuf::cow(SBuf::size_type newsize) } reAlloc(newsize); } - -std::size_t std::hash::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); -} diff --git a/src/SBuf.h b/src/SBuf.h index 5858a1ff0d..3cff0b4a4a 100644 --- a/src/SBuf.h +++ b/src/SBuf.h @@ -722,15 +722,6 @@ ToLower(SBuf buf) return buf; } -namespace std { - /// default hash functor to support std::unordered_map - template <> - struct hash - { - 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 index 0000000000..68ddfeb4e6 --- /dev/null +++ b/src/SBufAlgos.cc @@ -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::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); +} diff --git a/src/SBufAlgos.h b/src/SBufAlgos.h index 213e8cc9ae..a9ea4208e5 100644 --- a/src/SBufAlgos.h +++ b/src/SBufAlgos.h @@ -81,5 +81,14 @@ SBufContainerJoin(const Container &items, const SBuf& separator) return rv; } +namespace std { + /// default hash functor to support std::unordered_map + template <> + struct hash + { + size_t operator()(const SBuf &) const noexcept; + }; +} + #endif /* SQUID_SBUFALGOS_H_ */ diff --git a/src/tests/testSBuf.cc b/src/tests/testSBuf.cc index 25509cd9b4..a9207bc4ad 100644 --- a/src/tests/testSBuf.cc +++ b/src/tests/testSBuf.cc @@ -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"