From 0d7efaa2e3895d7d6664c93fa7ecb97d7237ca3b Mon Sep 17 00:00:00 2001 From: zlice Date: Wed, 16 Jul 2025 09:00:50 -0400 Subject: [PATCH 1/2] fix 32bit builds --- components/esm/formid.hpp | 8 ++++---- components/misc/strings/algorithm.hpp | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/components/esm/formid.hpp b/components/esm/formid.hpp index e9416e35c7..9fe89585c2 100644 --- a/components/esm/formid.hpp +++ b/components/esm/formid.hpp @@ -51,10 +51,10 @@ namespace std { size_t operator()(const ESM::FormId& formId) const { - static_assert(sizeof(ESM::FormId) == sizeof(size_t)); - size_t s; - memcpy(&s, &formId, sizeof(size_t)); - return hash()(s); + static_assert(sizeof(ESM::FormId) == sizeof(uint64_t)); + uint64_t s; + memcpy(&s, &formId, sizeof(ESM::FormId)); + return hash()(s); } }; diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index 18f72104bd..9b42588780 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -4,6 +4,7 @@ #include "lower.hpp" #include +#include #include #include #include @@ -88,14 +89,23 @@ namespace Misc::StringUtils constexpr std::size_t operator()(std::string_view str) const { // FNV-1a - std::size_t hash{ 0xcbf29ce484222325ull }; - constexpr std::size_t prime{ 0x00000100000001B3ull }; + std::uint64_t hash{ 0xcbf29ce484222325ull }; + constexpr std::uint64_t prime{ 0x00000100000001B3ull }; for (char c : str) { - hash ^= static_cast(toLower(c)); + hash ^= static_cast(toLower(c)); 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 {}; } }; From 485517cf64c83c86f398b3df0d8cc3c1ce6566a5 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 3 Aug 2025 20:52:16 +0200 Subject: [PATCH 2/2] Use std::hash --- components/misc/strings/algorithm.hpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/components/misc/strings/algorithm.hpp b/components/misc/strings/algorithm.hpp index 9b42588780..681bc0607a 100644 --- a/components/misc/strings/algorithm.hpp +++ b/components/misc/strings/algorithm.hpp @@ -86,7 +86,7 @@ namespace Misc::StringUtils { using is_transparent = void; - constexpr std::size_t operator()(std::string_view str) const + std::size_t operator()(std::string_view str) const { // FNV-1a std::uint64_t hash{ 0xcbf29ce484222325ull }; @@ -96,16 +96,7 @@ namespace Misc::StringUtils hash ^= static_cast(toLower(c)); hash *= prime; } - 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 {}; + return std::hash()(hash); } };