diff options
author | Noel Grandin <noel@peralex.com> | 2021-04-12 13:07:56 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-04-12 17:45:19 +0200 |
commit | fe23e35ba5705d7f51f69c3f4e7ccd6c5b575a6b (patch) | |
tree | bace053173689b600f8b6a75145e07cc2b933743 | |
parent | 27911b0455d8dcc08a0702372492a6ce00250cb7 (diff) |
less copying in SfxItemPropertyMap::getPropertyEntries
we can just expose the map now, and avoid copying all the properties
Change-Id: Icb22975508582268dfa96e41eb98ac01e7f51317
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113982
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | editeng/source/uno/unotext.cxx | 2 | ||||
-rw-r--r-- | include/svl/itemprop.hxx | 4 | ||||
-rw-r--r-- | linguistic/source/lngopt.cxx | 13 | ||||
-rw-r--r-- | reportdesign/source/ui/misc/UITools.cxx | 24 | ||||
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 9 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unopage.cxx | 11 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unopback.cxx | 22 | ||||
-rw-r--r-- | svl/source/items/itemprop.cxx | 13 | ||||
-rw-r--r-- | svx/source/unodraw/unoshape.cxx | 17 | ||||
-rw-r--r-- | sw/source/core/access/accpara.cxx | 18 | ||||
-rw-r--r-- | sw/source/core/unocore/unocrsrhelper.cxx | 8 | ||||
-rw-r--r-- | sw/source/core/unocore/unosrch.cxx | 451 | ||||
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 18 |
13 files changed, 237 insertions, 373 deletions
diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index 3c73fc75b31e..af0a3db58ce0 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -1270,7 +1270,7 @@ void SAL_CALL SvxUnoTextRangeBase::setAllPropertiesToDefault() { for (auto & entry : mpPropSet->getPropertyMap().getPropertyEntries()) { - _setPropertyToDefault( pForwarder, &entry, -1 ); + _setPropertyToDefault( pForwarder, &entry.second, -1 ); } } } diff --git a/include/svl/itemprop.hxx b/include/svl/itemprop.hxx index da183abecf7b..0fbbeaf08cb0 100644 --- a/include/svl/itemprop.hxx +++ b/include/svl/itemprop.hxx @@ -114,7 +114,6 @@ struct SfxItemPropertyNamedEntry : public SfxItemPropertySimpleEntry } }; -typedef std::vector< SfxItemPropertyNamedEntry > PropertyEntryVector_t; class SVL_DLLPUBLIC SfxItemPropertyMap { std::unordered_map< std::u16string_view, @@ -132,7 +131,8 @@ public: bool hasPropertyByName( std::u16string_view rName ) const; void mergeProperties( const css::uno::Sequence< css::beans::Property >& rPropSeq ); - PropertyEntryVector_t getPropertyEntries() const; + const std::unordered_map< std::u16string_view, + SfxItemPropertySimpleEntry >& getPropertyEntries() const { return m_aMap; } sal_uInt32 getSize() const; }; diff --git a/linguistic/source/lngopt.cxx b/linguistic/source/lngopt.cxx index a163b50dcad5..f7d7e4c0bf29 100644 --- a/linguistic/source/lngopt.cxx +++ b/linguistic/source/lngopt.cxx @@ -317,15 +317,12 @@ Sequence< PropertyValue > SAL_CALL { MutexGuard aGuard( GetLinguMutex() ); - PropertyEntryVector_t aPropEntries = aPropertyMap.getPropertyEntries(); std::vector<PropertyValue> aProps; - aProps.reserve(aPropertyMap.getSize()); - - std::transform(aPropEntries.begin(), aPropEntries.end(), std::back_inserter(aProps), - [this](PropertyEntryVector_t::const_reference rPropEntry) { - return PropertyValue(rPropEntry.sName, rPropEntry.nWID, - aConfig.GetProperty(rPropEntry.nWID), - css::beans::PropertyState_DIRECT_VALUE); }); + aProps.reserve(aPropertyMap.getPropertyEntries().size()); + for(auto & rPair : aPropertyMap.getPropertyEntries()) + aProps.push_back(PropertyValue(OUString(rPair.first), rPair.second.nWID, + aConfig.GetProperty(rPair.second.nWID), + css::beans::PropertyState_DIRECT_VALUE)); return comphelper::containerToSequence(aProps); } diff --git a/reportdesign/source/ui/misc/UITools.cxx b/reportdesign/source/ui/misc/UITools.cxx index 92785547d4d3..14262558618c 100644 --- a/reportdesign/source/ui/misc/UITools.cxx +++ b/reportdesign/source/ui/misc/UITools.cxx @@ -276,16 +276,15 @@ namespace uno::Reference< beans::XPropertySetInfo> xInfo = _xShape->getPropertySetInfo(); SvxUnoPropertyMapProvider aMap; const SfxItemPropertyMap& rPropertyMap = aMap.GetPropertySet(SVXMAP_CUSTOMSHAPE, SdrObject::GetGlobalDrawObjectItemPool())->getPropertyMap(); - PropertyEntryVector_t aPropVector = rPropertyMap.getPropertyEntries(); - for (const auto& rProp : aPropVector) + for (const auto& rProp : rPropertyMap.getPropertyEntries()) { - if ( xInfo->hasPropertyByName(rProp.sName) ) + if ( xInfo->hasPropertyByName(OUString(rProp.first)) ) { - const SfxPoolItem* pItem = _rItemSet.GetItem(rProp.nWID); + const SfxPoolItem* pItem = _rItemSet.GetItem(rProp.second.nWID); if ( pItem ) { - ::std::unique_ptr<SfxPoolItem> pClone(pItem->CloneSetWhich(rProp.nWID)); - pClone->PutValue(_xShape->getPropertyValue(rProp.sName), rProp.nMemberId); + ::std::unique_ptr<SfxPoolItem> pClone(pItem->CloneSetWhich(rProp.second.nWID)); + pClone->PutValue(_xShape->getPropertyValue(OUString(rProp.first)), rProp.second.nMemberId); _rItemSet.Put(std::move(pClone)); } } @@ -297,21 +296,20 @@ namespace const uno::Reference< beans::XPropertySetInfo> xInfo = _xShape->getPropertySetInfo(); SvxUnoPropertyMapProvider aMap; const SfxItemPropertyMap& rPropertyMap = aMap.GetPropertySet(SVXMAP_CUSTOMSHAPE, SdrObject::GetGlobalDrawObjectItemPool())->getPropertyMap(); - PropertyEntryVector_t aPropVector = rPropertyMap.getPropertyEntries(); - for (const auto& rProp : aPropVector) + for (const auto& rProp : rPropertyMap.getPropertyEntries()) { - if ( SfxItemState::SET == _rItemSet.GetItemState(rProp.nWID) && xInfo->hasPropertyByName(rProp.sName) ) + if ( SfxItemState::SET == _rItemSet.GetItemState(rProp.second.nWID) && xInfo->hasPropertyByName(OUString(rProp.first)) ) { - if ( ( rProp.nFlags & beans::PropertyAttribute::READONLY ) != beans::PropertyAttribute::READONLY ) + if ( ( rProp.second.nFlags & beans::PropertyAttribute::READONLY ) != beans::PropertyAttribute::READONLY ) { - const SfxPoolItem* pItem = _rItemSet.GetItem(rProp.nWID); + const SfxPoolItem* pItem = _rItemSet.GetItem(rProp.second.nWID); if ( pItem ) { uno::Any aValue; - pItem->QueryValue(aValue,rProp.nMemberId); + pItem->QueryValue(aValue,rProp.second.nMemberId); try { - _xShape->setPropertyValue(rProp.sName, aValue); + _xShape->setPropertyValue(OUString(rProp.first), aValue); } catch(uno::Exception&) { // shapes have a bug so we ignore this one. diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index e772f906303f..048e663d81ad 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1247,20 +1247,19 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, bool bCursor css::uno::Sequence< css::beans::PropertyValue > aProperties; sal_Int32 nCount = 0; const SfxItemPropertyMap& rMap = ScCellObj::GetCellPropertyMap(); - PropertyEntryVector_t aPropVector = rMap.getPropertyEntries(); for ( sal_uInt16 nWhich = ATTR_PATTERN_START; nWhich <= ATTR_PATTERN_END; ++nWhich ) { const SfxPoolItem* pItem = nullptr; if ( rNewSet.GetItemState( nWhich, true, &pItem ) == SfxItemState::SET && pItem ) { - for ( const auto& rProp : aPropVector) + for ( const auto& rProp : rMap.getPropertyEntries()) { - if ( rProp.nWID == nWhich ) + if ( rProp.second.nWID == nWhich ) { css::uno::Any aVal; - pItem->QueryValue( aVal, rProp.nMemberId ); + pItem->QueryValue( aVal, rProp.second.nMemberId ); aProperties.realloc( nCount + 1 ); - aProperties[ nCount ].Name = rProp.sName; + aProperties[ nCount ].Name = rProp.first; aProperties[ nCount ].Value = aVal; ++nCount; } diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx index 0aef28437972..02bd803cdeb9 100644 --- a/sd/source/ui/unoidl/unopage.cxx +++ b/sd/source/ui/unoidl/unopage.cxx @@ -2780,15 +2780,14 @@ void SdMasterPage::setBackground( const Any& rValue ) Reference< beans::XPropertySetInfo > xSetInfo( xInputSet->getPropertySetInfo(), UNO_SET_THROW ); Reference< beans::XPropertyState > xSetStates( xInputSet, UNO_QUERY ); - PropertyEntryVector_t aBackgroundProperties = ImplGetPageBackgroundPropertySet()->getPropertyMap().getPropertyEntries(); - for( const auto& rProp : aBackgroundProperties ) + for( const auto& rProp : ImplGetPageBackgroundPropertySet()->getPropertyMap().getPropertyEntries() ) { - if( xSetInfo->hasPropertyByName( rProp.sName ) ) + if( xSetInfo->hasPropertyByName( OUString(rProp.first) ) ) { - if( !xSetStates.is() || xSetStates->getPropertyState( rProp.sName ) == beans::PropertyState_DIRECT_VALUE ) - xStyleSet->setPropertyValue( rProp.sName, xInputSet->getPropertyValue( rProp.sName ) ); + if( !xSetStates.is() || xSetStates->getPropertyState( OUString(rProp.first) ) == beans::PropertyState_DIRECT_VALUE ) + xStyleSet->setPropertyValue( OUString(rProp.first), xInputSet->getPropertyValue( OUString(rProp.first) ) ); else - xSetStates->setPropertyToDefault( rProp.sName ); + xSetStates->setPropertyToDefault( OUString(rProp.first) ); } } } diff --git a/sd/source/ui/unoidl/unopback.cxx b/sd/source/ui/unoidl/unopback.cxx index 10aff03c05bf..60a1ac6bbe14 100644 --- a/sd/source/ui/unoidl/unopback.cxx +++ b/sd/source/ui/unoidl/unopback.cxx @@ -100,26 +100,24 @@ void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) if( mpPropSet->AreThereOwnUsrAnys() ) { - PropertyEntryVector_t aProperties = mpPropSet->getPropertyMap().getPropertyEntries(); - - for( const auto& rProp : aProperties ) + for( const auto& rProp : mpPropSet->getPropertyMap().getPropertyEntries() ) { - uno::Any* pAny = mpPropSet->GetUsrAnyForID( rProp ); + uno::Any* pAny = mpPropSet->GetUsrAnyForID( rProp.second ); if( pAny ) { - OUString aPropertyName( rProp.sName ); - switch( rProp.nWID ) + OUString aPropertyName( rProp.first ); + switch( rProp.second.nWID ) { case XATTR_FILLFLOATTRANSPARENCE : case XATTR_FILLGRADIENT : { if ( ( pAny->getValueType() == ::cppu::UnoType< css::awt::Gradient>::get() ) - && ( rProp.nMemberId == MID_FILLGRADIENT ) ) + && ( rProp.second.nMemberId == MID_FILLGRADIENT ) ) { setPropertyValue( aPropertyName, *pAny ); } else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) && - ( rProp.nMemberId == MID_NAME ) ) + ( rProp.second.nMemberId == MID_NAME ) ) { setPropertyValue( aPropertyName, *pAny ); } @@ -128,12 +126,12 @@ void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) case XATTR_FILLHATCH : { if ( ( pAny->getValueType() == ::cppu::UnoType< css::drawing::Hatch>::get() ) - && ( rProp.nMemberId == MID_FILLHATCH ) ) + && ( rProp.second.nMemberId == MID_FILLHATCH ) ) { setPropertyValue( aPropertyName, *pAny ); } else if ( ( pAny->getValueType() == ::cppu::UnoType<OUString>::get() ) && - ( rProp.nMemberId == MID_NAME ) ) + ( rProp.second.nMemberId == MID_NAME ) ) { setPropertyValue( aPropertyName, *pAny ); } @@ -141,13 +139,13 @@ void SdUnoPageBackground::fillItemSet( SdDrawDocument* pDoc, SfxItemSet& rSet ) break; case XATTR_FILLBITMAP : { - if (rProp.nMemberId == MID_BITMAP && + if (rProp.second.nMemberId == MID_BITMAP && (pAny->getValueType() == cppu::UnoType<css::awt::XBitmap>::get() || pAny->getValueType() == cppu::UnoType<css::graphic::XGraphic>::get())) { setPropertyValue( aPropertyName, *pAny ); } - else if (pAny->getValueType() == ::cppu::UnoType<OUString>::get() && rProp.nMemberId == MID_NAME) + else if (pAny->getValueType() == ::cppu::UnoType<OUString>::get() && rProp.second.nMemberId == MID_NAME) { setPropertyValue( aPropertyName, *pAny ); } diff --git a/svl/source/items/itemprop.cxx b/svl/source/items/itemprop.cxx index b704dbc80d95..7898464b9b84 100644 --- a/svl/source/items/itemprop.cxx +++ b/svl/source/items/itemprop.cxx @@ -112,19 +112,6 @@ void SfxItemPropertyMap::mergeProperties( const uno::Sequence< beans::Property > } } -PropertyEntryVector_t SfxItemPropertyMap::getPropertyEntries() const -{ - PropertyEntryVector_t aRet; - aRet.reserve(m_aMap.size()); - - for( const auto& rPair : m_aMap ) - { - const SfxItemPropertySimpleEntry* pEntry = &rPair.second; - aRet.emplace_back( OUString(rPair.first), *pEntry ); - } - return aRet; -} - sal_uInt32 SfxItemPropertyMap::getSize() const { return m_aMap.size(); diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx index de292ef43bb3..e645738d7a3b 100644 --- a/svx/source/unodraw/unoshape.cxx +++ b/svx/source/unodraw/unoshape.cxx @@ -591,26 +591,25 @@ static void SvxItemPropertySet_ObtainSettingsFromPropertySet(const SvxItemProper return; const SfxItemPropertyMap& rSrc = rPropSet.getPropertyMap(); - PropertyEntryVector_t aSrcPropVector = rSrc.getPropertyEntries(); - for(const auto& rSrcProp : aSrcPropVector) + for(const auto& rSrcProp : rSrc.getPropertyEntries()) { - const sal_uInt16 nWID = rSrcProp.nWID; + const sal_uInt16 nWID = rSrcProp.second.nWID; if(SfxItemPool::IsWhich(nWID) && (nWID < OWN_ATTR_VALUE_START || nWID > OWN_ATTR_VALUE_END) - && rPropSet.GetUsrAnyForID(rSrcProp)) + && rPropSet.GetUsrAnyForID(rSrcProp.second)) rSet.Put(rSet.GetPool()->GetDefaultItem(nWID)); } - for(const auto& rSrcProp : aSrcPropVector) + for(const auto& rSrcProp : rSrc.getPropertyEntries()) { - if(rSrcProp.nWID) + if(rSrcProp.second.nWID) { - uno::Any* pUsrAny = rPropSet.GetUsrAnyForID(rSrcProp); + uno::Any* pUsrAny = rPropSet.GetUsrAnyForID(rSrcProp.second); if(pUsrAny) { // search for equivalent entry in pDst - const SfxItemPropertySimpleEntry* pEntry = pMap->getByName( rSrcProp.sName ); + const SfxItemPropertySimpleEntry* pEntry = pMap->getByName( rSrcProp.first ); if(pEntry) { // entry found @@ -618,7 +617,7 @@ static void SvxItemPropertySet_ObtainSettingsFromPropertySet(const SvxItemProper { // special ID in PropertySet, can only be set // directly at the object - xSet->setPropertyValue( rSrcProp.sName, *pUsrAny); + xSet->setPropertyValue( OUString(rSrcProp.first), *pUsrAny); } else { diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index f8e9ac6d925c..e4008dc10a41 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1488,17 +1488,16 @@ void SwAccessibleParagraph::_getDefaultAttributesImpl( { const SfxItemPropertyMap& rPropMap = aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_CURSOR )->getPropertyMap(); - PropertyEntryVector_t aPropertyEntries = rPropMap.getPropertyEntries(); - for ( const auto& rProp : aPropertyEntries ) + for ( const auto& rPair : rPropMap.getPropertyEntries() ) { - const SfxPoolItem* pItem = pSet->GetItem( rProp.nWID ); + const SfxPoolItem* pItem = pSet->GetItem( rPair.second.nWID ); if ( pItem ) { uno::Any aVal; - pItem->QueryValue( aVal, rProp.nMemberId ); + pItem->QueryValue( aVal, rPair.second.nMemberId ); PropertyValue rPropVal; - rPropVal.Name = rProp.sName; + rPropVal.Name = rPair.first; rPropVal.Value = aVal; rPropVal.Handle = -1; rPropVal.State = beans::PropertyState_DEFAULT_VALUE; @@ -1681,19 +1680,18 @@ void SwAccessibleParagraph::_getRunAttributesImpl( const SfxItemPropertyMap& rPropMap = aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_CURSOR )->getPropertyMap(); - PropertyEntryVector_t aPropertyEntries = rPropMap.getPropertyEntries(); - for ( const auto& rProp : aPropertyEntries ) + for ( const auto& rPair : rPropMap.getPropertyEntries() ) { const SfxPoolItem* pItem( nullptr ); // #i82637# - Found character attributes, whose value equals the value of // the corresponding default character attributes, are excluded. - if ( aSet.GetItemState( rProp.nWID, true, &pItem ) == SfxItemState::SET ) + if ( aSet.GetItemState( rPair.second.nWID, true, &pItem ) == SfxItemState::SET ) { uno::Any aVal; - pItem->QueryValue( aVal, rProp.nMemberId ); + pItem->QueryValue( aVal, rPair.second.nMemberId ); PropertyValue rPropVal; - rPropVal.Name = rProp.sName; + rPropVal.Name = rPair.first; rPropVal.Value = aVal; rPropVal.Handle = -1; rPropVal.State = PropertyState_DIRECT_VALUE; diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 1abb9f207cf2..fdcdb0f76c1e 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -317,13 +317,13 @@ static uno::Any GetParaListAutoFormat(SwTextNode const& rNode) SfxItemPropertyMap const& rMap(rPropSet.getPropertyMap()); std::vector<beans::NamedValue> props; // have to iterate the map, not the item set? - for (auto const& rEntry : rMap.getPropertyEntries()) + for (auto const& rPair : rMap.getPropertyEntries()) { - if (rPropSet.getPropertyState(rEntry, rSet) == PropertyState_DIRECT_VALUE) + if (rPropSet.getPropertyState(rPair.second, rSet) == PropertyState_DIRECT_VALUE) { Any value; - rPropSet.getPropertyValue(rEntry, rSet, value); - props.emplace_back(rEntry.sName, value); + rPropSet.getPropertyValue(rPair.second, rSet, value); + props.emplace_back(OUString(rPair.first), value); } } return uno::makeAny(comphelper::containerToSequence(props)); diff --git a/sw/source/core/unocore/unosrch.cxx b/sw/source/core/unocore/unosrch.cxx index cb826a2b439b..0c4e6a50aee7 100644 --- a/sw/source/core/unocore/unosrch.cxx +++ b/sw/source/core/unocore/unosrch.cxx @@ -40,8 +40,8 @@ using namespace ::com::sun::star; class SwSearchProperties_Impl { - std::unique_ptr<std::unique_ptr<beans::PropertyValue>[]> pValueArr; - const PropertyEntryVector_t aPropertyEntries; + std::unordered_map<OUString, beans::PropertyValue> maValues; + SfxItemPropertyMap mrMap; SwSearchProperties_Impl(const SwSearchProperties_Impl&) = delete; SwSearchProperties_Impl& operator=(const SwSearchProperties_Impl&) = delete; @@ -60,48 +60,32 @@ public: }; SwSearchProperties_Impl::SwSearchProperties_Impl() : - aPropertyEntries( aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)->getPropertyMap().getPropertyEntries() ) + mrMap( aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR)->getPropertyMap() ) { - size_t nArrLen = aPropertyEntries.size(); - pValueArr.reset( new std::unique_ptr<beans::PropertyValue>[nArrLen] ); } void SwSearchProperties_Impl::SetProperties(const uno::Sequence< beans::PropertyValue >& aSearchAttribs) { //delete all existing values - for(size_t i = 0; i < aPropertyEntries.size(); ++i) - { - pValueArr[i].reset(); - } + maValues.clear(); for(const beans::PropertyValue& rSearchAttrib : aSearchAttribs) { const OUString& sName = rSearchAttrib.Name; - auto aIt = std::find_if(aPropertyEntries.begin(), aPropertyEntries.end(), - [&sName](const SfxItemPropertyNamedEntry& rProp) { return rProp.sName == sName; }); - if( aIt == aPropertyEntries.end() ) + if( !mrMap.hasPropertyByName(sName) ) throw beans::UnknownPropertyException(sName); - auto nIndex = static_cast<sal_uInt32>(std::distance(aPropertyEntries.begin(), aIt)); - pValueArr[nIndex].reset( new beans::PropertyValue(rSearchAttrib) ); + maValues[sName] = rSearchAttrib; } } uno::Sequence< beans::PropertyValue > SwSearchProperties_Impl::GetProperties() const { - sal_uInt32 nPropCount = 0; - for( size_t i = 0; i < aPropertyEntries.size(); i++) - if(pValueArr[i]) - nPropCount++; - - uno::Sequence< beans::PropertyValue > aRet(nPropCount); + uno::Sequence< beans::PropertyValue > aRet(maValues.size()); beans::PropertyValue* pProps = aRet.getArray(); - nPropCount = 0; - for(size_t i = 0; i < aPropertyEntries.size(); i++) + sal_Int32 nPropCount = 0; + for(auto const & rPair : maValues) { - if(pValueArr[i]) - { - pProps[nPropCount++] = *(pValueArr[i]); - } + pProps[nPropCount++] = rPair.second; } return aRet; } @@ -157,270 +141,177 @@ void SwSearchProperties_Impl::FillItemSet(SfxItemSet& rSet, bool bIsValueSearch) pCTLWeightItem, pShadowItem ; - PropertyEntryVector_t::const_iterator aIt = aPropertyEntries.begin(); - for(size_t i = 0; i < aPropertyEntries.size(); i++, ++aIt) + auto funcClone = [&rSet](sal_uInt16 nWID, std::unique_ptr<SfxPoolItem> & rpPoolItem) + { + if(!rpPoolItem) + rpPoolItem.reset(rSet.GetPool()->GetDefaultItem(nWID).Clone()); + return rpPoolItem.get(); + }; + for(auto const & rPair : maValues) { - if(pValueArr[i]) + SfxPoolItem* pTempItem = nullptr; + const SfxItemPropertySimpleEntry & rPropEntry = mrMap.getPropertyEntries().find(std::u16string_view(rPair.first))->second; + sal_uInt16 nWID = rPropEntry.nWID; + switch(nWID) { - SfxPoolItem* pTempItem = nullptr; - switch(aIt->nWID) - { - case RES_BOX: - if(!pBoxItem) - pBoxItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pBoxItem.get(); - break; - case RES_CHRATR_BOX: - if(!pCharBoxItem) - pCharBoxItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCharBoxItem.get(); - break; - case RES_BREAK: - if(!pBreakItem) - pBreakItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pBreakItem.get(); - break; - case RES_CHRATR_AUTOKERN: - if(!pAutoKernItem) - pAutoKernItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pAutoKernItem.get(); - break; - case RES_CHRATR_BACKGROUND: - if(!pBrushItem) - pBrushItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pBrushItem.get(); - break; - case RES_CHRATR_CASEMAP: - if(!pCasemapItem) - pCasemapItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCasemapItem.get(); - break; - case RES_CHRATR_COLOR: - if(!pCharColorItem) - pCharColorItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCharColorItem.get(); - break; - case RES_CHRATR_CONTOUR: - if(!pContourItem) - pContourItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pContourItem.get(); - break; - case RES_CHRATR_CROSSEDOUT: - if(!pCrossedOutItem) - pCrossedOutItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCrossedOutItem.get(); - break; - case RES_CHRATR_ESCAPEMENT: - if(!pEscItem) - pEscItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pEscItem.get(); - break; - case RES_CHRATR_BLINK: - if(!pBlinkItem) - pBlinkItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pBlinkItem.get(); - break; - case RES_CHRATR_FONT: - if(!pFontItem) - pFontItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pFontItem.get(); - break; - case RES_CHRATR_FONTSIZE: - if(!pFontSizeItem) - pFontSizeItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pFontSizeItem.get(); - break; - case RES_CHRATR_KERNING: - if(!pKernItem) - pKernItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pKernItem.get(); - break; - case RES_CHRATR_LANGUAGE: - if(!pLangItem) - pLangItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pLangItem.get(); - break; - case RES_CHRATR_NOHYPHEN: - if(!pNHyphItem) - pNHyphItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pNHyphItem.get(); - break; - case RES_CHRATR_POSTURE: - if(!pPostItem) - pPostItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pPostItem.get(); - break; - case RES_CHRATR_SHADOWED: - if(!pShadItem) - pShadItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pShadItem.get(); - break; - case RES_TXTATR_CHARFMT: - if(!pCharFormatItem) - pCharFormatItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCharFormatItem.get(); - break; - case RES_CHRATR_UNDERLINE: - if(!pULineItem) - pULineItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pULineItem.get(); - break; - case RES_CHRATR_OVERLINE: - if(!pOLineItem) - pOLineItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pOLineItem.get(); - break; - case RES_CHRATR_WEIGHT: - if(!pWeightItem) - pWeightItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pWeightItem.get(); - break; - case RES_PARATR_DROP: - if(!pDropItem) - pDropItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pDropItem.get(); - break; - case RES_TXTATR_INETFMT: - if(!pInetItem) - pInetItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pInetItem.get(); - break; - case RES_PAGEDESC: - if(!pDescItem) - pDescItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pDescItem.get(); - break; - case RES_PARATR_ADJUST: - if(!pAdjItem) - pAdjItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pAdjItem.get(); - break; - case RES_BACKGROUND: - if(!pBackItem) - pBackItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pBackItem.get(); - break; - case RES_UL_SPACE: - if(!pULItem) - pULItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pULItem.get(); - break; - case RES_LR_SPACE: - if(!pLRItem) - pLRItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pLRItem.get(); - break; - case RES_KEEP: - if(!pKeepItem) - pKeepItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pKeepItem.get(); - break; - case RES_LINENUMBER: - if(!pLineNumItem) - pLineNumItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pLineNumItem.get(); - break; - case RES_PARATR_LINESPACING: - if(!pLineSpaceItem) - pLineSpaceItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pLineSpaceItem.get(); - break; - case RES_PARATR_REGISTER: - if(!pRegItem) - pRegItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pRegItem.get(); - break; - case RES_PARATR_SPLIT: - if(!pSplitItem) - pSplitItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pSplitItem.get(); - break; - case RES_PARATR_TABSTOP: - if(!pTabItem) - pTabItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pTabItem.get(); - break; - case RES_CHRATR_WORDLINEMODE: - if(!pWLineItem) - pWLineItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pWLineItem.get(); - break; - case RES_CHRATR_CJK_FONT: - if(!pFontCJKItem ) - pFontCJKItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pFontCJKItem.get(); - break; - case RES_CHRATR_CJK_FONTSIZE: - if(!pFontSizeCJKItem ) - pFontSizeCJKItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pFontSizeCJKItem.get(); - break; - case RES_CHRATR_CJK_LANGUAGE: - if(!pCJKLangItem ) - pCJKLangItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCJKLangItem.get(); - break; - case RES_CHRATR_CJK_POSTURE: - if(!pCJKPostureItem ) - pCJKPostureItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCJKPostureItem.get(); - break; - case RES_CHRATR_CJK_WEIGHT: - if(!pCJKWeightItem ) - pCJKWeightItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCJKWeightItem.get(); - break; - case RES_CHRATR_CTL_FONT: - if(!pFontCTLItem ) - pFontCTLItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pFontCTLItem.get(); - break; - case RES_CHRATR_CTL_FONTSIZE: - if(!pFontSizeCTLItem ) - pFontSizeCTLItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pFontSizeCTLItem.get(); - break; - case RES_CHRATR_CTL_LANGUAGE: - if(!pCTLLangItem ) - pCTLLangItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCTLLangItem.get(); - break; - case RES_CHRATR_CTL_POSTURE: - if(!pCTLPostureItem ) - pCTLPostureItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCTLPostureItem.get(); - break; - case RES_CHRATR_CTL_WEIGHT: - if(!pCTLWeightItem ) - pCTLWeightItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pCTLWeightItem.get(); - break; - case RES_CHRATR_SHADOW: - if(!pShadowItem ) - pShadowItem.reset(rSet.GetPool()->GetDefaultItem(aIt->nWID).Clone()); - pTempItem = pShadowItem.get(); - break; - } - if(pTempItem) + case RES_BOX: + pTempItem = funcClone(nWID, pBoxItem); + break; + case RES_CHRATR_BOX: + pTempItem = funcClone(nWID, pCharBoxItem); + break; + case RES_BREAK: + pTempItem = funcClone(nWID, pBreakItem); + break; + case RES_CHRATR_AUTOKERN: + pTempItem = funcClone(nWID, pAutoKernItem); + break; + case RES_CHRATR_BACKGROUND: + pTempItem = funcClone(nWID, pBrushItem); + break; + case RES_CHRATR_CASEMAP: + pTempItem = funcClone(nWID, pCasemapItem); + break; + case RES_CHRATR_COLOR: + pTempItem = funcClone(nWID, pCharColorItem); + break; + case RES_CHRATR_CONTOUR: + pTempItem = funcClone(nWID, pContourItem); + break; + case RES_CHRATR_CROSSEDOUT: + pTempItem = funcClone(nWID, pCrossedOutItem); + break; + case RES_CHRATR_ESCAPEMENT: + pTempItem = funcClone(nWID, pEscItem); + break; + case RES_CHRATR_BLINK: + pTempItem = funcClone(nWID, pBlinkItem); + break; + case RES_CHRATR_FONT: + pTempItem = funcClone(nWID, pFontItem); + break; + case RES_CHRATR_FONTSIZE: + pTempItem = funcClone(nWID, pFontSizeItem); + break; + case RES_CHRATR_KERNING: + pTempItem = funcClone(nWID, pKernItem); + break; + case RES_CHRATR_LANGUAGE: + pTempItem = funcClone(nWID, pLangItem); + break; + case RES_CHRATR_NOHYPHEN: + pTempItem = funcClone(nWID, pNHyphItem); + break; + case RES_CHRATR_POSTURE: + pTempItem = funcClone(nWID, pPostItem); + break; + case RES_CHRATR_SHADOWED: + pTempItem = funcClone(nWID, pShadItem); + break; + case RES_TXTATR_CHARFMT: + pTempItem = funcClone(nWID, pCharFormatItem); + break; + case RES_CHRATR_UNDERLINE: + pTempItem = funcClone(nWID, pULineItem); + break; + case RES_CHRATR_OVERLINE: + pTempItem = funcClone(nWID, pOLineItem); + break; + case RES_CHRATR_WEIGHT: + pTempItem = funcClone(nWID, pWeightItem); + break; + case RES_PARATR_DROP: + pTempItem = funcClone(nWID, pDropItem); + break; + case RES_TXTATR_INETFMT: + pTempItem = funcClone(nWID, pInetItem); + break; + case RES_PAGEDESC: + pTempItem = funcClone(nWID, pDescItem); + break; + case RES_PARATR_ADJUST: + pTempItem = funcClone(nWID, pAdjItem); + break; + case RES_BACKGROUND: + pTempItem = funcClone(nWID, pBackItem); + break; + case RES_UL_SPACE: + pTempItem = funcClone(nWID, pULItem); + break; + case RES_LR_SPACE: + pTempItem = funcClone(nWID, pLRItem); + break; + case RES_KEEP: + pTempItem = funcClone(nWID, pKeepItem); + break; + case RES_LINENUMBER: + pTempItem = funcClone(nWID, pLineNumItem); + break; + case RES_PARATR_LINESPACING: + pTempItem = funcClone(nWID, pLineSpaceItem); + break; + case RES_PARATR_REGISTER: + pTempItem = funcClone(nWID, pRegItem); + break; + case RES_PARATR_SPLIT: + pTempItem = funcClone(nWID, pSplitItem); + break; + case RES_PARATR_TABSTOP: + pTempItem = funcClone(nWID, pTabItem); + break; + case RES_CHRATR_WORDLINEMODE: + pTempItem = funcClone(nWID, pWLineItem); + break; + case RES_CHRATR_CJK_FONT: + pTempItem = funcClone(nWID, pFontCJKItem); + break; + case RES_CHRATR_CJK_FONTSIZE: + pTempItem = funcClone(nWID, pFontSizeCJKItem); + break; + case RES_CHRATR_CJK_LANGUAGE: + pTempItem = funcClone(nWID, pCJKLangItem); + break; + case RES_CHRATR_CJK_POSTURE: + pTempItem = funcClone(nWID, pCJKPostureItem); + break; + case RES_CHRATR_CJK_WEIGHT: + pTempItem = funcClone(nWID, pCJKWeightItem); + break; + case RES_CHRATR_CTL_FONT: + pTempItem = funcClone(nWID, pFontCTLItem); + break; + case RES_CHRATR_CTL_FONTSIZE: + pTempItem = funcClone(nWID, pFontSizeCTLItem); + break; + case RES_CHRATR_CTL_LANGUAGE: + pTempItem = funcClone(nWID, pCTLLangItem); + break; + case RES_CHRATR_CTL_POSTURE: + pTempItem = funcClone(nWID, pCTLPostureItem); + break; + case RES_CHRATR_CTL_WEIGHT: + pTempItem = funcClone(nWID, pCTLWeightItem); + break; + case RES_CHRATR_SHADOW: + pTempItem = funcClone(nWID, pShadowItem); + break; + } + if(pTempItem) + { + if(bIsValueSearch) { - if(bIsValueSearch) - { - pTempItem->PutValue(pValueArr[i]->Value, aIt->nMemberId); - rSet.Put(*pTempItem); - } - else - rSet.InvalidateItem( pTempItem->Which() ); + pTempItem->PutValue(rPair.second.Value, rPropEntry.nMemberId); + rSet.Put(*pTempItem); } + else + rSet.InvalidateItem( pTempItem->Which() ); } } } bool SwSearchProperties_Impl::HasAttributes() const { - for(size_t i = 0; i < aPropertyEntries.size(); i++) - if(pValueArr[i]) - return true; - return false; + return !maValues.empty(); } SwXTextSearch::SwXTextSearch() : diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 9c0e9d5ff968..3c70dc9eaa93 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1138,17 +1138,16 @@ namespace { class SwStyleProperties_Impl { - const PropertyEntryVector_t aPropertyEntries; + const SfxItemPropertyMap& mrMap; std::map<OUString, uno::Any> m_vPropertyValues; public: explicit SwStyleProperties_Impl(const SfxItemPropertyMap& rMap) - : aPropertyEntries(rMap.getPropertyEntries()) + : mrMap(rMap) { } - bool AllowsKey(const OUString& rName) + bool AllowsKey(std::u16string_view rName) { - return std::any_of(aPropertyEntries.begin(), aPropertyEntries.end(), - [rName] (const SfxItemPropertyNamedEntry& rEntry) {return rName == rEntry.sName;} ); + return mrMap.hasPropertyByName(rName); } bool SetProperty(const OUString& rName, const uno::Any& rValue) { @@ -4269,7 +4268,6 @@ uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties() const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet(nPropSetId); const SfxItemPropertyMap &rMap = pPropSet->getPropertyMap(); - PropertyEntryVector_t aPropVector = rMap.getPropertyEntries(); SfxItemSet& rSet = *mpSet; SfxItemIter aIter(rSet); @@ -4280,13 +4278,13 @@ uno::Sequence< beans::PropertyValue > SwXAutoStyle::getProperties() // TODO: Optimize - and fix! the old iteration filled each WhichId // only once but there are more properties than WhichIds - for( const auto& rProp : aPropVector ) + for( const auto& rPair : rMap.getPropertyEntries() ) { - if ( rProp.nWID == nWID ) + if ( rPair.second.nWID == nWID ) { beans::PropertyValue aPropertyValue; - aPropertyValue.Name = rProp.sName; - pItem->QueryValue( aPropertyValue.Value, rProp.nMemberId ); + aPropertyValue.Name = rPair.first; + pItem->QueryValue( aPropertyValue.Value, rPair.second.nMemberId ); aPropertyVector.push_back( aPropertyValue ); } } |