1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00

Use Fowler-Noll-Vo hash instead of std::hash

This commit is contained in:
Evil Eye 2022-08-14 19:55:32 +02:00
parent 16922f8000
commit de8d9b8db3

View File

@ -71,8 +71,15 @@ namespace Misc::StringUtils
std::size_t operator()(std::string_view str) const
{
// TODO avoid string copy
return std::hash<std::string>{}(lowerCase(str));
// FNV-1a
std::size_t hash{0xcbf29ce484222325ull};
constexpr std::size_t prime{0x00000100000001B3ull};
for(char c : str)
{
hash ^= static_cast<std::size_t>(toLower(c));
hash *= prime;
}
return hash;
}
};