From bb5425ed3d8cc04e4242059a17912752d6b48c53 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 28 Aug 2021 18:53:07 +0200 Subject: tdf#135683 speed up writer layout cache access can be hot, so use a std::unordered_map Change-Id: I70e34e80cad67536414c71facbe0222dd88c65a7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121208 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/o3tl/hash_combine.hxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include/o3tl/hash_combine.hxx') diff --git a/include/o3tl/hash_combine.hxx b/include/o3tl/hash_combine.hxx index 139ee981699c..f56beda62672 100644 --- a/include/o3tl/hash_combine.hxx +++ b/include/o3tl/hash_combine.hxx @@ -11,6 +11,17 @@ namespace o3tl { +template +inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const* pValue, size_t nCount) +{ + static_assert(sizeof(nSeed) == 4); + for (size_t i = 0; i < nCount; ++i) + { + nSeed ^= std::hash{}(*pValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 2); + ++pValue; + } +} + template inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const& nValue) { @@ -18,6 +29,17 @@ inline std::enable_if_t<(sizeof(N) == 4)> hash_combine(N& nSeed, T const& nValue nSeed ^= std::hash{}(nValue) + 0x9E3779B9u + (nSeed << 6) + (nSeed >> 2); } +template +inline std::enable_if_t<(sizeof(N) == 8)> hash_combine(N& nSeed, T const* pValue, size_t nCount) +{ + static_assert(sizeof(nSeed) == 8); + for (size_t i = 0; i < nCount; ++i) + { + nSeed ^= std::hash{}(*pValue) + 0x9E3779B97F4A7C15llu + (nSeed << 12) + (nSeed >> 4); + ++pValue; + } +} + template inline std::enable_if_t<(sizeof(N) == 8)> hash_combine(N& nSeed, T const& nValue) { -- cgit