diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-04-18 18:43:44 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-04-18 20:12:18 +0200 |
commit | 9cff36d37df95bb9d2b552259c718459b2f81682 (patch) | |
tree | 154b3becac129cce5bcbf230ea18a94d8ddb5fab /svx | |
parent | 957c54e504846f16dfbb40bc0b6811b5c1817eb4 (diff) |
reduce allocation cost in SvxShape::SetProperty
use std::optional so we don't need to heap allocate all the time.
note that I couldn't use the normal SfxItemSet constructor,
std::optional::emplace on macOS doesn't seem to play nice with
the template magic there
Change-Id: Ic5de23e9a20dceae56f894cf0706b89ced77ff58
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114246
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/unodraw/unoshape.cxx | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index a111ea46be04..33549e3c7978 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -88,6 +88,7 @@ #include <svx/svdopath.hxx> #include <memory> +#include <optional> #include <vector> #include <iostream> @@ -106,7 +107,7 @@ class GDIMetaFile; struct SvxShapeImpl { SvxShape& mrAntiImpl; - std::unique_ptr<SfxItemSet> mpItemSet; + std::optional<SfxItemSet> mxItemSet; sal_uInt32 mnObjId; SvxShapeMaster* mpMaster; bool mbHasSdrObjectOwnership; @@ -1653,22 +1654,26 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any& throw IllegalArgumentException(); } + std::optional<SfxItemSet> xLocalSet; SfxItemSet* pSet; if( mbIsMultiPropertyCall && !bIsNotPersist ) { - if( mpImpl->mpItemSet == nullptr ) + if( !mpImpl->mxItemSet ) { - mpImpl->mpItemSet.reset(new SfxItemSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}})); + sal_uInt16 aWhichPairTable[] = { pMap->nWID, pMap->nWID, 0, 0 }; + mpImpl->mxItemSet.emplace( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(), aWhichPairTable); } else { - mpImpl->mpItemSet->MergeRange(pMap->nWID, pMap->nWID); + mpImpl->mxItemSet->MergeRange(pMap->nWID, pMap->nWID); } - pSet = mpImpl->mpItemSet.get(); + pSet = &*mpImpl->mxItemSet; } else { - pSet = new SfxItemSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}}); + sal_uInt16 aWhichPairTable[] = { pMap->nWID, pMap->nWID, 0, 0 }; + xLocalSet.emplace( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(), aWhichPairTable); + pSet = &*xLocalSet; } if( pSet->GetItemState( pMap->nWID ) != SfxItemState::SET ) @@ -1702,18 +1707,13 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any& { // set not-persistent attribute extra GetSdrObject()->ApplyNotPersistAttr( *pSet ); - delete pSet; } else { // if we have a XMultiProperty call then the item set // will be set in setPropertyValues later if( !mbIsMultiPropertyCall ) - { GetSdrObject()->SetMergedItemSetAndBroadcast( *pSet ); - - delete pSet; - } } } @@ -1828,15 +1828,15 @@ void SAL_CALL SvxShape::setPropertyValues( const css::uno::Sequence< OUString >& } } - if( mpImpl->mpItemSet && HasSdrObject() ) - GetSdrObject()->SetMergedItemSetAndBroadcast( *mpImpl->mpItemSet ); + if( mpImpl->mxItemSet && HasSdrObject() ) + GetSdrObject()->SetMergedItemSetAndBroadcast( *mpImpl->mxItemSet ); } void SvxShape::endSetPropertyValues() { mbIsMultiPropertyCall = false; - mpImpl->mpItemSet.reset(); + mpImpl->mxItemSet.reset(); } |