From de8d9b8db39133130b89dadb7ed28c72a60848bb Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 14 Aug 2022 19:55:32 +0200 Subject: [PATCH] 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; } };