From 258aec223aada068df5f8705b6a0972696835f2e Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 2 Apr 2023 15:00:03 +0200 Subject: [PATCH] Shift record type value for IndexRefId hash --- apps/openmw_test_suite/esm/testrefid.cpp | 16 ++++++++++++++++ components/esm/indexrefid.hpp | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/openmw_test_suite/esm/testrefid.cpp b/apps/openmw_test_suite/esm/testrefid.cpp index 51dad424d0..ded1c0353e 100644 --- a/apps/openmw_test_suite/esm/testrefid.cpp +++ b/apps/openmw_test_suite/esm/testrefid.cpp @@ -196,6 +196,22 @@ namespace ESM EXPECT_NE(stringRefId, formIdRefId); } + TEST(ESMRefIdTest, indexRefIdHashDiffersForDistinctValues) + { + const RefId a = RefId::index(static_cast(3), 1); + const RefId b = RefId::index(static_cast(3), 2); + std::hash hash; + EXPECT_NE(hash(a), hash(b)); + } + + TEST(ESMRefIdTest, indexRefIdHashDiffersForDistinctRecords) + { + const RefId a = RefId::index(static_cast(1), 3); + const RefId b = RefId::index(static_cast(2), 3); + std::hash hash; + EXPECT_NE(hash(a), hash(b)); + } + struct ESMRefIdToStringTest : TestWithParam> { }; diff --git a/components/esm/indexrefid.hpp b/components/esm/indexrefid.hpp index 006dfd39ed..283126f90c 100644 --- a/components/esm/indexrefid.hpp +++ b/components/esm/indexrefid.hpp @@ -53,7 +53,7 @@ namespace std { std::size_t operator()(ESM::IndexRefId value) const noexcept { - return std::hash{}(static_cast(value.mRecordType) | value.mValue); + return std::hash{}((static_cast(value.mRecordType) << 32) | value.mValue); } }; }