1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 23:45:35 +00:00

Merge branch 'fnv_support' into 'master'

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

See merge request OpenMW/openmw!2273
This commit is contained in:
psi29a 2022-08-15 08:01:00 +00:00
commit cdec6495aa

View file

@ -69,10 +69,17 @@ 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
{
// 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;
}
};