1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-10-18 04:46:46 +00:00

fix 32bit builds

This commit is contained in:
zlice 2025-07-16 09:00:50 -04:00 committed by Evil Eye
parent b9a28dab3e
commit 0d7efaa2e3
2 changed files with 18 additions and 8 deletions

View file

@ -51,10 +51,10 @@ namespace std
{ {
size_t operator()(const ESM::FormId& formId) const size_t operator()(const ESM::FormId& formId) const
{ {
static_assert(sizeof(ESM::FormId) == sizeof(size_t)); static_assert(sizeof(ESM::FormId) == sizeof(uint64_t));
size_t s; uint64_t s;
memcpy(&s, &formId, sizeof(size_t)); memcpy(&s, &formId, sizeof(ESM::FormId));
return hash<size_t>()(s); return hash<uint64_t>()(s);
} }
}; };

View file

@ -4,6 +4,7 @@
#include "lower.hpp" #include "lower.hpp"
#include <algorithm> #include <algorithm>
#include <cstdint>
#include <functional> #include <functional>
#include <string> #include <string>
#include <string_view> #include <string_view>
@ -88,14 +89,23 @@ namespace Misc::StringUtils
constexpr std::size_t operator()(std::string_view str) const constexpr std::size_t operator()(std::string_view str) const
{ {
// FNV-1a // FNV-1a
std::size_t hash{ 0xcbf29ce484222325ull }; std::uint64_t hash{ 0xcbf29ce484222325ull };
constexpr std::size_t prime{ 0x00000100000001B3ull }; constexpr std::uint64_t prime{ 0x00000100000001B3ull };
for (char c : str) for (char c : str)
{ {
hash ^= static_cast<std::size_t>(toLower(c)); hash ^= static_cast<std::uint64_t>(toLower(c));
hash *= prime; hash *= prime;
} }
return hash; if constexpr (sizeof(std::uint64_t) <= sizeof(std::size_t))
return hash;
else if constexpr (sizeof(std::uint32_t) == sizeof(std::size_t))
{
std::uint32_t low = hash & 0xFFFFFFFF;
std::uint32_t high = hash >> 32;
return low ^ high;
}
static_assert(sizeof(std::uint64_t) <= sizeof(std::size_t) || sizeof(std::uint32_t) == sizeof(std::size_t));
return {};
} }
}; };