sc/source/core/data/patattr.cxx |   33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

New commits:
commit ba9ac212f9f175b6eed6f569f4d5d3fcf2a8cee3
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jun 8 10:31:39 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jun 8 16:11:56 2023 +0200

    ScPatternAttr does not need a special case for *mxHashCode == 0
    
    I don't why the original
        commit   b26c34267cdf9d0b7ba4e2fda7ae706d5cd76299
        replace SfxPoolItem::LookupHashCode() with Lookup() (tdf#135215)
    did this.
    After I can tell, the Lookup will function perfectly fine with hashcode
    == 0, the operator== method already falls back to using full comparison
    of the underlying SfxItemSets
    
    After this change, running 'make sc.check' with
    ScPatternAttr::CalcHashCode patched to always return 0 reveals no
    problems.
    
    Change-Id: I56c3e6c00796e4cc9c12fd460181d6ca1ec6f066
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152732
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index 73dd29fe6501..96abc6676cba 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -169,19 +169,16 @@ SfxPoolItem::lookup_iterator 
ScPatternAttr::Lookup(lookup_iterator begin, lookup
 {
     if( !mxHashCode )
         CalcHashCode();
-    if( *mxHashCode != 0 )
+    for( auto it = begin; it != end; ++it)
     {
-        for( auto it = begin; it != end; ++it)
+        const ScPatternAttr* other = static_cast<const ScPatternAttr*>(*it);
+        if( !other->mxHashCode )
+            other->CalcHashCode();
+        if (*mxHashCode == *other->mxHashCode
+            && EqualPatternSets( GetItemSet(), other->GetItemSet())
+            && StrCmp( GetStyleName(), other->GetStyleName()))
         {
-            const ScPatternAttr* other = static_cast<const 
ScPatternAttr*>(*it);
-            if( !other->mxHashCode )
-                other->CalcHashCode();
-            if (*mxHashCode == *other->mxHashCode
-                && EqualPatternSets( GetItemSet(), other->GetItemSet())
-                && StrCmp( GetStyleName(), other->GetStyleName()))
-            {
-                return it;
-            }
+            return it;
         }
     }
     return end;
@@ -1426,18 +1423,12 @@ sal_uInt64 ScPatternAttr::GetKey() const
 void ScPatternAttr::CalcHashCode() const
 {
     auto const & rSet = GetItemSet();
-    if( rSet.TotalCount() != compareSize ) // see EqualPatternSets()
-    {
-        mxHashCode = 0; // invalid
-        return;
-    }
     // 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_uInt32 h1 = 1;
-    sal_uInt32 h2 = 1;
-    sal_uInt32 h3 = 1;
-    sal_uInt32 h4 = 1;
+    sal_uInt32 h1 = 0;
+    sal_uInt32 h2 = 0;
+    sal_uInt32 h3 = 0;
+    sal_uInt32 h4 = 0;
     for (auto it = rSet.GetItems_Impl(), end = rSet.GetItems_Impl() + 
(compareSize / 4 * 4); it != end; )
     {
         h1 = 31 * h1 + reinterpret_cast<size_t>(*it);

Reply via email to