From de8d9b8db39133130b89dadb7ed28c72a60848bb Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 14 Aug 2022 19:55:32 +0200 Subject: [PATCH 1/2] Use Fowler-Noll-Vo hash instead of std::hash --- components/misc/strings/algorithm.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index e6ee29c341..156a7c5a14 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -71,8 +71,15 @@ namespace Misc::StringUtils std::size_t operator()(std::string_view str) const { - // TODO avoid string copy - return std::hash{}(lowerCase(str)); + // FNV-1a + std::size_t hash{0xcbf29ce484222325ull}; + constexpr std::size_t prime{0x00000100000001B3ull}; + for(char c : str) + { + hash ^= static_cast(toLower(c)); + hash *= prime; + } + return hash; } }; From e6868fd2111921f68a70185247b36d0f27c58756 Mon Sep 17 00:00:00 2001 From: Matt <3397065-ZehMatt@users.noreply.gitlab.com> Date: Sun, 14 Aug 2022 19:06:29 +0000 Subject: [PATCH 2/2] Allow constexpr hashing --- components/misc/strings/algorithm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index 156a7c5a14..0b6e2ef9bd 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -69,7 +69,7 @@ namespace Misc::StringUtils { using is_transparent = void; - std::size_t operator()(std::string_view str) const + constexpr std::size_t operator()(std::string_view str) const { // FNV-1a std::size_t hash{0xcbf29ce484222325ull};