diff --git a/include/boost/static_string/config.hpp b/include/boost/static_string/config.hpp index 2217fe8..79861f7 100644 --- a/include/boost/static_string/config.hpp +++ b/include/boost/static_string/config.hpp @@ -14,6 +14,17 @@ // Are we dependent on Boost? // #define BOOST_STATIC_STRING_STANDALONE +#include + +// detect 32/64 bit +#if UINTPTR_MAX == UINT64_MAX +#define BOOST_STATIC_STRING_ARCH 64 +#elif UINTPTR_MAX == UINT32_MAX +#define BOOST_STATIC_STRING_ARCH 32 +#else +#error Unknown or unsupported architecture, please open an issue +#endif + // Can we have deduction guides? #if __cpp_deduction_guides >= 201703L #define BOOST_STATIC_STRING_USE_DEDUCT diff --git a/include/boost/static_string/static_string.hpp b/include/boost/static_string/static_string.hpp index fae3dea..7b36a93 100644 --- a/include/boost/static_string/static_string.hpp +++ b/include/boost/static_string/static_string.hpp @@ -6376,39 +6376,30 @@ struct hash< return std::hash()(view_type(str.data(), str.size())); #else std::size_t seed = 0; - for (CharT const& c : str) { - mix_impl(std::integral_constant= 8>{}, seed, c); + for (CharT const& c : str) + { +#if BOOST_STATIC_STRING_ARCH == 64 + seed += 0x9e3779b9 + std::hash()( c ); + std::size_t const m = (std::size_t(0xe9846af) << 32) + 0x9b1a615d; + seed ^= seed >> 32; + seed *= m; + seed ^= seed >> 32; + seed *= m; + seed ^= seed >> 28; +#elif BOOST_STATIC_STRING_ARCH == 32 + seed += 0x9e3779b9 + std::hash()( c ); + std::size_t const m1 = 0x21f0aaad; + std::size_t const m2 = 0x735a2d97; + seed ^= seed >> 16; + seed *= m1; + seed ^= seed >> 15; + seed *= m2; + seed ^= seed >> 15; +#endif } return seed; #endif } - - static - void - mix_impl(std::true_type, std::size_t& seed, CharT c) - { - seed += 0x9e3779b9 + std::hash()( c ); - std::size_t const m = (std::size_t(0xe9846af) << 32) + 0x9b1a615d; - seed ^= seed >> 32; - seed *= m; - seed ^= seed >> 32; - seed *= m; - seed ^= seed >> 28; - } - - static - void - mix_impl(std::false_type, std::size_t& seed, CharT c) - { - seed += 0x9e3779b9 + std::hash()( c ); - std::size_t const m1 = 0x21f0aaad; - std::size_t const m2 = 0x735a2d97; - seed ^= seed >> 16; - seed *= m1; - seed ^= seed >> 15; - seed *= m2; - seed ^= seed >> 15; - } }; } // std