From e5fe8434110c1299527a0d03bf450e1b6d08ca57 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 1 Jun 2023 14:35:24 +0200 Subject: use a SIMD friendly hashcode for ScPatternAttr which shaves 5% off load time of a large sheet with lots of formats. We are calculating a hash over a decent sized array of pointers, so unroll the loop and reduce data-dependencies to give the compiler (and the CPU) a chance to do work in parallel Change-Id: I3d58fcf547c9280437295b9c9ec10aff16419afc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152443 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/core/data/patattr.cxx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'sc/source') diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx index 532831f90a78..d2be666aa349 100644 --- a/sc/source/core/data/patattr.cxx +++ b/sc/source/core/data/patattr.cxx @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -64,7 +65,6 @@ #include #include #include -#include #include #include @@ -1432,8 +1432,25 @@ void ScPatternAttr::CalcHashCode() const mxHashCode = 0; // invalid return; } - mxHashCode = 1; // Set up seed so that an empty pattern does not have an (invalid) hash of 0. - boost::hash_range(*mxHashCode, rSet.GetItems_Impl(), rSet.GetItems_Impl() + compareSize); + // This is an unrolled hash function so the compiler/CPU can execute it in parallel, + // because we hit this hard when loading documents with lots of styles. + // Set up seed so that an empty pattern does not have an (invalid) hash of 0. + sal_Int32 h1 = 1; + sal_Int32 h2 = 1; + sal_Int32 h3 = 1; + sal_Int32 h4 = 1; + for (auto it = rSet.GetItems_Impl(), end = rSet.GetItems_Impl() + (compareSize / 4 * 4); it != end; ) + { + h1 = 31 * h1 + reinterpret_cast(*it); + ++it; + h2 = 31 * h2 + reinterpret_cast(*it); + ++it; + h3 = 31 * h3 + reinterpret_cast(*it); + ++it; + h4 = 31 * h4 + reinterpret_cast(*it); + ++it; + } + mxHashCode = h1 + h2 + h3 + h4; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit