[Libreoffice-commits] core.git: sc/inc sc/source
Noel Grandin (via logerrit)
logerrit at kemper.freedesktop.org
Sun Dec 29 06:53:04 UTC 2019
sc/inc/patattr.hxx | 4 ++++
sc/source/core/data/patattr.cxx | 34 +++++++++++++++++++++++++++++-----
2 files changed, 33 insertions(+), 5 deletions(-)
New commits:
commit 8f25472d3de4f43cf594fa41ebfba2a1b01d4c9d
Author: Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Sat Dec 28 12:49:41 2019 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Dec 29 07:52:32 2019 +0100
tdf#129228 speedup opening of xlsx file with lots of comments
by avoid some of the EqualPatternSets memcmp cost by using a
hashcode, memcmp with lots of large and similar arrays ends up
blowing the L1/L2 cache
Takes the time from 64s to 59s for me.
Change-Id: I6961aa34f4e7457a70cb75a37dfae50d5f328589
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85918
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/patattr.hxx b/sc/inc/patattr.hxx
index 9ecc7c0d4e22..d5f170db4a4a 100644
--- a/sc/inc/patattr.hxx
+++ b/sc/inc/patattr.hxx
@@ -52,6 +52,7 @@ enum ScAutoFontColorMode
class SC_DLLPUBLIC ScPatternAttr final : public SfxSetItem
{
o3tl::optional<OUString> pName;
+ mutable o3tl::optional<size_t> mxHashCode;
ScStyleSheet* pStyle;
sal_uInt64 mnKey;
public:
@@ -143,6 +144,9 @@ public:
void SetKey(sal_uInt64 nKey);
sal_uInt64 GetKey() const;
+
+private:
+ void CalcHashCode() const;
};
#endif
diff --git a/sc/source/core/data/patattr.cxx b/sc/source/core/data/patattr.cxx
index c2a293cc04b4..fc562b4b6092 100644
--- a/sc/source/core/data/patattr.cxx
+++ b/sc/source/core/data/patattr.cxx
@@ -62,6 +62,7 @@
#include <validat.hxx>
#include <scmod.hxx>
#include <fillinfo.hxx>
+#include <boost/functional/hash.hpp>
using sc::HMMToTwips;
using sc::TwipsToHMM;
@@ -140,9 +141,17 @@ bool ScPatternAttr::operator==( const SfxPoolItem& rCmp ) const
{
// #i62090# Use quick comparison between ScPatternAttr's ItemSets
- return SfxPoolItem::operator==(rCmp) &&
- EqualPatternSets( GetItemSet(), static_cast<const ScPatternAttr&>(rCmp).GetItemSet() ) &&
- StrCmp( GetStyleName(), static_cast<const ScPatternAttr&>(rCmp).GetStyleName() );
+ if (!SfxPoolItem::operator==(rCmp) )
+ return false;
+ if (!mxHashCode)
+ CalcHashCode();
+ auto const & rOther = static_cast<const ScPatternAttr&>(rCmp);
+ if (!rOther.mxHashCode)
+ rOther.CalcHashCode();
+ if (*mxHashCode != *rOther.mxHashCode)
+ return false;
+ return EqualPatternSets( GetItemSet(), rOther.GetItemSet() ) &&
+ StrCmp( GetStyleName(), rOther.GetStyleName() );
}
SvxCellOrientation ScPatternAttr::GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
@@ -881,8 +890,10 @@ void ScPatternAttr::GetFromEditItemSet( SfxItemSet& rDestSet, const SfxItemSet&
void ScPatternAttr::GetFromEditItemSet( const SfxItemSet* pEditSet )
{
- if( pEditSet )
- GetFromEditItemSet( GetItemSet(), *pEditSet );
+ if( !pEditSet )
+ return;
+ GetFromEditItemSet( GetItemSet(), *pEditSet );
+ mxHashCode.reset();
}
void ScPatternAttr::FillEditParaItems( SfxItemSet* pEditSet ) const
@@ -923,13 +934,19 @@ void ScPatternAttr::DeleteUnchanged( const ScPatternAttr* pOldAttrs )
{
// item is set in OldAttrs (or its parent) -> compare pointers
if ( pThisItem == pOldItem )
+ {
rThisSet.ClearItem( nSubWhich );
+ mxHashCode.reset();
+ }
}
else if ( eOldState != SfxItemState::DONTCARE )
{
// not set in OldAttrs -> compare item value to default item
if ( *pThisItem == rThisSet.GetPool()->GetDefaultItem( nSubWhich ) )
+ {
rThisSet.ClearItem( nSubWhich );
+ mxHashCode.reset();
+ }
}
}
}
@@ -949,6 +966,7 @@ void ScPatternAttr::ClearItems( const sal_uInt16* pWhich )
SfxItemSet& rSet = GetItemSet();
for (sal_uInt16 i=0; pWhich[i]; i++)
rSet.ClearItem(pWhich[i]);
+ mxHashCode.reset();
}
static SfxStyleSheetBase* lcl_CopyStyleToPool
@@ -1346,4 +1364,10 @@ sal_uInt64 ScPatternAttr::GetKey() const
return mnKey;
}
+void ScPatternAttr::CalcHashCode() const
+{
+ auto const & rSet = GetItemSet();
+ mxHashCode = boost::hash_range(rSet.GetItems_Impl(), rSet.GetItems_Impl() + rSet.Count());
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list