diff options
| author | Sergio Losilla | 2020-11-17 11:16:36 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-05-09 18:05:14 +0200 |
| commit | cdf4748d1c082a29b328d14e0967fe0fa76a26ff (patch) | |
| tree | 6dbe730ad11d645ce5f8043baac383445fce2957 /src/catch2/internal | |
| parent | 520b6dace90223753ad46615db9734089dbbdad3 (diff) | |
| download | catch3-cdf4748d1c082a29b328d14e0967fe0fa76a26ff.tar.gz | |
Modified hash to make it more independent of the choice of test names.
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_test_case_registry_impl.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp index 7f7f101d..d142f045 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.cpp +++ b/src/catch2/internal/catch_test_case_registry_impl.cpp @@ -22,24 +22,27 @@ namespace Catch { namespace { - struct HashTest { - explicit HashTest(SimplePcg32& rng_inst) { - basis = rng_inst(); - basis <<= 32; - basis |= rng_inst(); - } + struct TestHasher { + using hash_t = uint64_t; + + explicit TestHasher( hash_t hashSuffix ): + m_hashSuffix( hashSuffix ) {} - uint64_t basis; + uint64_t m_hashSuffix; - uint64_t operator()(TestCaseInfo const& t) const { - // Modified FNV-1a hash - static constexpr uint64_t prime = 1099511628211; - uint64_t hash = basis; + uint32_t operator()( TestCaseInfo const& t ) const { + // FNV-1a hash with multiplication fold. + const hash_t prime = 1099511628211u; + hash_t hash = 14695981039346656037u; for (const char c : t.name) { hash ^= c; hash *= prime; } - return hash; + hash ^= m_hashSuffix; + hash *= prime; + const uint32_t low{ static_cast<uint32_t>(hash) }; + const uint32_t high{ static_cast<uint32_t>(hash >> 32) }; + return low * high; } }; } // end anonymous namespace @@ -56,8 +59,8 @@ namespace { } case TestRunOrder::Randomized: { seedRng(config); - HashTest h(rng()); - std::vector<std::pair<uint64_t, TestCaseHandle>> indexed_tests; + TestHasher h{ config.rngSeed() }; + std::vector<std::pair<TestHasher::hash_t, TestCaseHandle>> indexed_tests; indexed_tests.reserve(unsortedTestCases.size()); for (auto const& handle : unsortedTestCases) { |