diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-01-06 14:15:44 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-01-09 15:43:39 +0100 |
commit | 9ba45189c76373d0464cc06902270914888162a3 (patch) | |
tree | 6598e37b8127749b42b37e978f4f1b5518b1fa65 | |
parent | 74a37dce322d56251edfa49e7b98a2195f8c8e45 (diff) |
make SdrCustomShapeGeometryItem sortable and fast (bsc#1183308)
The document contains a complex graphic consisting of many shapes,
and SfxItemPool tries to avoid duplicates by checking for equality.
And SdrCustomShapeGeometryItem contains a UNO sequence as data,
and comparing those is non-trivial. Make the item sortable, which
should make things faster, and use anyLess() for the ordering.
Additionally first check the size of the list of property names
the class keeps for an easy fast return.
Change-Id: I49220e589b6510c6f1f40d584301be83367fb5a4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128047
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r-- | include/svx/sdasitm.hxx | 3 | ||||
-rw-r--r-- | svx/source/items/customshapeitem.cxx | 32 |
2 files changed, 31 insertions, 4 deletions
diff --git a/include/svx/sdasitm.hxx b/include/svx/sdasitm.hxx index 620e805b5813..ebd022980e6e 100644 --- a/include/svx/sdasitm.hxx +++ b/include/svx/sdasitm.hxx @@ -62,6 +62,9 @@ private: SdrCustomShapeGeometryItem & operator =(SdrCustomShapeGeometryItem &&) = delete; // due to SfxPoolItem virtual bool operator==( const SfxPoolItem& ) const override; + virtual bool operator<( const SfxPoolItem& ) const override; + virtual bool IsSortable() const override { return true; } + virtual bool GetPresentation(SfxItemPresentation ePresentation, MapUnit eCoreMetric, MapUnit ePresentationMetric, OUString &rText, const IntlWrapper&) const override; diff --git a/svx/source/items/customshapeitem.cxx b/svx/source/items/customshapeitem.cxx index 733b30f29e47..0bba5ca6eb33 100644 --- a/svx/source/items/customshapeitem.cxx +++ b/svx/source/items/customshapeitem.cxx @@ -20,6 +20,7 @@ #include <sal/config.h> #include <o3tl/any.hxx> +#include <comphelper/anycompare.hxx> #include <svx/sdasitm.hxx> #include <com/sun/star/beans/PropertyValue.hpp> @@ -216,12 +217,35 @@ void SdrCustomShapeGeometryItem::ClearPropertyValue( const OUString& rPropName ) SdrCustomShapeGeometryItem::~SdrCustomShapeGeometryItem() { } + bool SdrCustomShapeGeometryItem::operator==( const SfxPoolItem& rCmp ) const { - bool bRet = SfxPoolItem::operator==( rCmp ); - if ( bRet ) - bRet = static_cast<const SdrCustomShapeGeometryItem&>(rCmp).aPropSeq == aPropSeq; - return bRet; + if( !SfxPoolItem::operator==( rCmp )) + return false; + const SdrCustomShapeGeometryItem& other = static_cast<const SdrCustomShapeGeometryItem&>(rCmp); + // This is called often by SfxItemPool, and comparing uno sequences is relatively slow. + // Optimize by checking the list of properties that this class keeps for the sequence, + // if the sizes are different, the sequences are different too, which should allow a cheap + // return for many cases. + if( aPropHashMap.size() != other.aPropHashMap.size()) + return false; + if( aPropPairHashMap.size() != other.aPropPairHashMap.size()) + return false; + return aPropSeq == other.aPropSeq; +} + +bool SdrCustomShapeGeometryItem::operator<( const SfxPoolItem& rCmp ) const +{ + assert(dynamic_cast<const SdrCustomShapeGeometryItem*>( &rCmp )); + const SdrCustomShapeGeometryItem& other = static_cast<const SdrCustomShapeGeometryItem&>(rCmp); + // Again, optimize by checking the list of properties and compare by their count if different + // (this is operator< for sorting purposes, so the ordering can be somewhat arbitrary). + if( aPropHashMap.size() != other.aPropHashMap.size()) + return aPropHashMap.size() < other.aPropHashMap.size(); + if( aPropPairHashMap.size() != other.aPropPairHashMap.size()) + return aPropPairHashMap.size() < other.aPropPairHashMap.size(); + return comphelper::anyLess( css::uno::makeAny( aPropSeq ), + css::uno::makeAny( other.aPropSeq )); } bool SdrCustomShapeGeometryItem::GetPresentation( |