From 014065015a6a3a79c7786f22b65c99f856e413a0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Fri, 14 Nov 2014 16:29:00 -0500 Subject: Convert llhash() to use boost::hash, per Cinder's suggestion. --- indra/llcommon/llhash.h | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'indra') diff --git a/indra/llcommon/llhash.h b/indra/llcommon/llhash.h index c077ebe93f..4b58e81565 100755 --- a/indra/llcommon/llhash.h +++ b/indra/llcommon/llhash.h @@ -27,26 +27,7 @@ #ifndef LL_LLHASH_H #define LL_LLHASH_H -#include "llpreprocessor.h" // for GCC_VERSION - -#if (LL_WINDOWS) -#include -#include -#elif LL_DARWIN || LL_LINUX -# if GCC_VERSION >= 40300 // gcc 4.3 and up -# include -# elif GCC_VERSION >= 30400 // gcc 3.4 and up -# include -# elif __GNUC__ >= 3 -# include -# else -# include -# endif -#elif LL_SOLARIS -#include -#else -#error Please define your platform. -#endif +#include // Warning - an earlier template-based version of this routine did not do // the correct thing on Windows. Since this is only used to get @@ -55,17 +36,17 @@ inline size_t llhash( const char * value ) { -#if LL_WINDOWS - return stdext::hash_value(value); -#elif ( (defined _STLPORT_VERSION) || ((LL_LINUX) && (__GNUC__ <= 2)) ) - std::hash H; - return H(value); -#elif LL_DARWIN || LL_LINUX || LL_SOLARIS - __gnu_cxx::hash H; - return H(value); -#else -#error Please define your platform. -#endif + // boost::hash is defined for std::string and for char, but there's no + // special overload for const char*. The lazy approach would be to + // instantiate a std::string and take its hash, but that might be more + // overhead than our callers want. Or we could use boost::hash_range() -- + // but that would require a preliminary pass over the value to determine + // the end iterator. Instead, use boost::hash_combine() to hash individual + // characters. + std::size_t seed = 0; + for ( ; *value; ++value) + boost::hash_combine(seed, *value); + return seed; } #endif -- cgit v1.2.3