Merge branch 'fnv_support' into 'master'

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

See merge request OpenMW/openmw!2273
update_coverity_image
psi29a 2 years ago
commit cdec6495aa

@ -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;
}
};

Loading…
Cancel
Save