summaryrefslogtreecommitdiff
path: root/include/svl
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2024-07-21 14:35:21 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-07-22 11:29:32 +0200
commitc3e8dbc139c3b1644ea07101a8c1111572ffa017 (patch)
tree0c7bc8971c9093308c887c163a0bda4c4a19c92c /include/svl
parent3133788fb5b8598ae275c566a9f55f88a668abf3 (diff)
Improve the perf for pool item scanning..
for large complex documents with lots of shapes. When that happens, we spend a lot of time scanning the std::unordered_set inside DefaultItemInstanceManager. Since most of our items are already capable of being hashed, and thus avoiding the scanning cost, make it so we can use the HashableItemInstanceManager most of the time. Change-Id: I43f4c04e956d316c976bea67d1941529d2d91182 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170813 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins Tested-by: Armin Le Grand <Armin.Le.Grand@me.com> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/svl')
-rw-r--r--include/svl/cintitem.hxx12
-rw-r--r--include/svl/eitem.hxx10
-rw-r--r--include/svl/poolitem.hxx14
3 files changed, 28 insertions, 8 deletions
diff --git a/include/svl/cintitem.hxx b/include/svl/cintitem.hxx
index d9c0f273f260..17becbaba92c 100644
--- a/include/svl/cintitem.hxx
+++ b/include/svl/cintitem.hxx
@@ -35,6 +35,9 @@ public:
virtual bool operator ==(const SfxPoolItem & rItem) const override;
+ virtual bool supportsHashCode() const override;
+ virtual size_t hashCode() const override final;
+
virtual bool GetPresentation(SfxItemPresentation,
MapUnit, MapUnit,
OUString & rText,
@@ -66,6 +69,9 @@ public:
virtual bool operator ==(const SfxPoolItem & rItem) const override;
+ virtual bool supportsHashCode() const override final;
+ virtual size_t hashCode() const override final;
+
virtual bool GetPresentation(SfxItemPresentation,
MapUnit, MapUnit,
OUString & rText,
@@ -98,6 +104,9 @@ public:
virtual bool operator ==(const SfxPoolItem & rItem) const override;
+ virtual bool supportsHashCode() const override final;
+ virtual size_t hashCode() const override final;
+
virtual bool GetPresentation(SfxItemPresentation,
MapUnit, MapUnit,
OUString & rText,
@@ -130,6 +139,9 @@ public:
virtual bool operator ==(const SfxPoolItem & rItem) const override;
+ virtual bool supportsHashCode() const override final;
+ virtual size_t hashCode() const override final;
+
virtual bool GetPresentation(SfxItemPresentation,
MapUnit, MapUnit,
OUString & rText,
diff --git a/include/svl/eitem.hxx b/include/svl/eitem.hxx
index f6fb22bfeb7d..fd398e8f0cbb 100644
--- a/include/svl/eitem.hxx
+++ b/include/svl/eitem.hxx
@@ -62,6 +62,16 @@ public:
return SfxEnumItemInterface::operator==(other) &&
m_nValue == static_cast<const SfxEnumItem<EnumT> &>(other).m_nValue;
}
+
+ virtual bool supportsHashCode() const override final
+ {
+ return true;
+ }
+
+ virtual size_t hashCode() const override final
+ {
+ return Which() ^ GetEnumValue();
+ }
};
class SVL_DLLPUBLIC SfxBoolItem
diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index 722c30df2bee..60b6ae98068b 100644
--- a/include/svl/poolitem.hxx
+++ b/include/svl/poolitem.hxx
@@ -675,6 +675,9 @@ public:
virtual bool operator==( const SfxPoolItem& ) const = 0;
bool operator!=( const SfxPoolItem& rItem ) const
{ return !(*this == rItem); }
+ // Used by HashedItemInstanceManager
+ virtual bool supportsHashCode() const;
+ virtual size_t hashCode() const;
/** @return true if it has a valid string representation */
virtual bool GetPresentation( SfxItemPresentation ePresentation,
@@ -762,14 +765,12 @@ private:
for specific PoolItem subclasses that can be hashed which is faster than using
the linear search with operator== that DefaultItemInstanceManager has to do
*/
-class HashedItemInstanceManager : public ItemInstanceManager
+class HashedItemInstanceManager final : public ItemInstanceManager
{
struct ItemHash {
- HashedItemInstanceManager& mrManager;
- ItemHash(HashedItemInstanceManager& rManager) : mrManager(rManager) {}
size_t operator()(const SfxPoolItem* p) const
{
- return mrManager.hashCode(*p);
+ return p->hashCode();
}
};
struct ItemEqual {
@@ -781,13 +782,10 @@ class HashedItemInstanceManager : public ItemInstanceManager
std::unordered_set<const SfxPoolItem*, ItemHash, ItemEqual> maRegistered;
-protected:
- virtual size_t hashCode(const SfxPoolItem&) const = 0;
-
public:
HashedItemInstanceManager(SfxItemType aSfxItemType)
: ItemInstanceManager(aSfxItemType)
- , maRegistered(0, ItemHash(*this), ItemEqual())
+ , maRegistered(0, ItemHash(), ItemEqual())
{
}