diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-13 09:02:48 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-14 06:00:49 +0200 |
commit | 8a017d25a62e878fdd32f189f0663b05d2ffb9cf (patch) | |
tree | c91ee53b5d9276ae30df785b52579a1b77a057df /writerfilter | |
parent | 17d3cacfb9675268e709cfc95771ad4ce8bde75a (diff) |
Avoid COW overhead using css::uno::Sequence
The scenarios are:
1. Calling sequence's begin() and end() in pairs to pass to algorithms
(both calls use getArray(), which does the COW checks)
2. In addition to #1, calling end() again when checking result of find
algorithms, and/or begin() to calculate result's distance
3. Using non-const sequences in range-based for loops, which internally
do #1
4. Assigning sequence to another sequence variable, and then modifying
one of them
In many cases, the sequences could be made const, or treated as const
for the purposes of the algorithms (using std::as_const, std::cbegin,
and std::cend). Where algorithm modifies the sequence, it was changed
to only call getArray() once. For that, css::uno::toNonConstRange was
introduced, which returns a struct (sublclass of std::pair) with two
iterators [begin, end], that are calculated using one call to begin()
and one call to getLength().
To handle #4, css::uno::Sequence::swap was introduced, that swaps the
internal pointer to uno_Sequence. So when a local Sequence variable
should be assigned to another variable, and the latter will be modified
further, it's now possible to use swap instead, so the two sequences
are kept independent.
The modified places were found by temporarily removing non-const end().
Change-Id: I8fe2787f200eecb70744e8b77fbdf7a49653f628
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123542
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 4 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapperTableHandler.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 12 | ||||
-rw-r--r-- | writerfilter/source/dmapper/GraphicImport.cxx | 2 | ||||
-rw-r--r-- | writerfilter/source/dmapper/NumberingManager.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/dmapper/StyleSheetTable.cxx | 2 |
7 files changed, 20 insertions, 22 deletions
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index b3d77b6a3887..5278206552f8 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1024,7 +1024,7 @@ static bool lcl_emptyRow(std::vector<RowSequence_t>& rTableRanges, sal_Int32 nRo return false; } - RowSequence_t rRowSeq = rTableRanges[nRow]; + const RowSequence_t rRowSeq = rTableRanges[nRow]; if (!rRowSeq.hasElements()) { SAL_WARN("writerfilter.dmapper", "m_aCellProperties not in sync with rTableRanges?"); @@ -1107,7 +1107,7 @@ css::uno::Sequence<css::beans::PropertyValues> DomainMapperTableHandler::endTabl // table style has got bigger precedence than docDefault style, // but lower precedence than the paragraph styles and direct paragraph formatting -void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParagraph rParaProp, std::vector< PropertyIds > aAllTableParaProperties, css::beans::PropertyValues rCellProperties) +void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParagraph rParaProp, std::vector< PropertyIds > aAllTableParaProperties, const css::beans::PropertyValues rCellProperties) { for( auto const& eId : aAllTableParaProperties ) { diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx index 5a2a37acd90f..4e396b6b23fc 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx @@ -90,7 +90,7 @@ public: */ void startTable(const TablePropertyMapPtr& pProps); - void ApplyParagraphPropertiesFromTableStyle(TableParagraph rParaProp, std::vector< PropertyIds > aAllTableProperties, css::beans::PropertyValues rCellProperties); + void ApplyParagraphPropertiesFromTableStyle(TableParagraph rParaProp, std::vector< PropertyIds > aAllTableProperties, const css::beans::PropertyValues rCellProperties); /// Handle end of table. void endTable(unsigned int nestedTableLevel, bool bTableStartsAtCellStart); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 65550495b1e1..c8e5ee0fb912 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -7832,9 +7832,9 @@ uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharSt } uno::Sequence<beans::PropertyValue> aProps; xLevels->getByIndex(nListLevel) >>= aProps; - auto pProp = std::find_if(aProps.begin(), aProps.end(), + auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps), [](const beans::PropertyValue& rProp) { return rProp.Name == "CharStyleName"; }); - if (pProp != aProps.end()) + if (pProp != std::cend(aProps)) { OUString aCharStyle; pProp->Value >>= aCharStyle; @@ -7903,9 +7903,9 @@ sal_Int32 DomainMapper_Impl::getNumberingProperty(const sal_Int32 nListId, sal_I { uno::Sequence<beans::PropertyValue> aProps; xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; - auto pProp = std::find_if(aProps.begin(), aProps.end(), + auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps), [&aProp](const beans::PropertyValue& rProp) { return rProp.Name == aProp; }); - if (pProp != aProps.end()) + if (pProp != std::cend(aProps)) pProp->Value >>= nRet; } } @@ -7934,9 +7934,9 @@ sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(const OUString& aProp) { uno::Sequence<beans::PropertyValue> aProps; xNumberingRules->getByIndex(nNumberingLevel) >>= aProps; - auto pPropVal = std::find_if(aProps.begin(), aProps.end(), + auto pPropVal = std::find_if(std::cbegin(aProps), std::cend(aProps), [&aProp](const beans::PropertyValue& rProp) { return rProp.Name == aProp; }); - if (pPropVal != aProps.end()) + if (pPropVal != std::cend(aProps)) pPropVal->Value >>= nRet; } diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx index e0a2828b5606..ec16cdd3b36e 100644 --- a/writerfilter/source/dmapper/GraphicImport.cxx +++ b/writerfilter/source/dmapper/GraphicImport.cxx @@ -803,7 +803,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue) xShapeProps->getPropertyValue("InteropGrabBag") >>= aGrabBag; // if the shape contains effects in the grab bag, we should not transform it // in a XTextContent so those effects can be preserved - bool bContainsEffects = std::any_of(aGrabBag.begin(), aGrabBag.end(), [](const auto& rProp) { + bool bContainsEffects = std::any_of(std::cbegin(aGrabBag), std::cend(aGrabBag), [](const auto& rProp) { return rProp.Name == "EffectProperties" || rProp.Name == "3DEffectProperties" || rProp.Name == "ArtisticEffectProperties"; diff --git a/writerfilter/source/dmapper/NumberingManager.cxx b/writerfilter/source/dmapper/NumberingManager.cxx index 51484b74408f..852d5e611750 100644 --- a/writerfilter/source/dmapper/NumberingManager.cxx +++ b/writerfilter/source/dmapper/NumberingManager.cxx @@ -172,13 +172,11 @@ uno::Sequence< beans::PropertyValue > ListLevel::GetCharStyleProperties( ) { PropertyValueVector_t rProperties; - uno::Sequence< beans::PropertyValue > vPropVals = PropertyMap::GetPropertyValues(); - beans::PropertyValue* aValIter = vPropVals.begin(); - beans::PropertyValue* aEndIter = vPropVals.end(); + const uno::Sequence< beans::PropertyValue > vPropVals = PropertyMap::GetPropertyValues(); const bool bIsSymbol(GetBulletChar().getLength() <= 1); - for( ; aValIter != aEndIter; ++aValIter ) - if (! IgnoreForCharStyle(aValIter->Name, bIsSymbol)) - rProperties.emplace_back(aValIter->Name, 0, aValIter->Value, beans::PropertyState_DIRECT_VALUE); + for( const auto& rPropNal : vPropVals ) + if (! IgnoreForCharStyle(rPropNal.Name, bIsSymbol)) + rProperties.emplace_back(rPropNal.Name, 0, rPropNal.Value, beans::PropertyState_DIRECT_VALUE); return comphelper::containerToSequence(rProperties); } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 920874afa39d..393d49839cc9 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -168,7 +168,7 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues( bool bChar { uno::Sequence< beans::PropertyValue > aSeq; rPropPair.second.getValue() >>= aSeq; - std::copy(aSeq.begin(), aSeq.end(), pCellGrabBagValues + nCellGrabBagValue); + std::copy(std::cbegin(aSeq), std::cend(aSeq), pCellGrabBagValues + nCellGrabBagValue); nCellGrabBagValue += aSeq.getLength(); } else @@ -1988,19 +1988,19 @@ void SectionPropertyMap::ApplyProperties_( const uno::Reference< beans::XPropert std::vector< uno::Any > vValues; { // Convert GetPropertyValues() value into something useful - uno::Sequence< beans::PropertyValue > vPropVals = GetPropertyValues(); + const uno::Sequence< beans::PropertyValue > vPropVals = GetPropertyValues(); //Temporarily store the items that are in grab bags uno::Sequence< beans::PropertyValue > vCharVals; uno::Sequence< beans::PropertyValue > vParaVals; - beans::PropertyValue* pCharGrabBag = std::find_if( vPropVals.begin(), vPropVals.end(), NamedPropertyValue( "CharInteropGrabBag" ) ); + const beans::PropertyValue* pCharGrabBag = std::find_if( vPropVals.begin(), vPropVals.end(), NamedPropertyValue( "CharInteropGrabBag" ) ); if ( pCharGrabBag != vPropVals.end() ) (pCharGrabBag->Value) >>= vCharVals; - beans::PropertyValue* pParaGrabBag = std::find_if( vPropVals.begin(), vPropVals.end(), NamedPropertyValue( "ParaInteropGrabBag" ) ); + const beans::PropertyValue* pParaGrabBag = std::find_if( vPropVals.begin(), vPropVals.end(), NamedPropertyValue( "ParaInteropGrabBag" ) ); if ( pParaGrabBag != vPropVals.end() ) (pParaGrabBag->Value) >>= vParaVals; - for ( beans::PropertyValue* pIter = vPropVals.begin(); pIter != vPropVals.end(); ++pIter ) + for ( const beans::PropertyValue* pIter = vPropVals.begin(); pIter != vPropVals.end(); ++pIter ) { if ( pIter != pCharGrabBag && pIter != pParaGrabBag && pIter->Name != "IsProtected" //section-only property diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx index 4e51aa0aecbb..0074fb948a12 100644 --- a/writerfilter/source/dmapper/StyleSheetTable.cxx +++ b/writerfilter/source/dmapper/StyleSheetTable.cxx @@ -350,7 +350,7 @@ void StyleSheetTable_Impl::SetPropertiesToDefault(const uno::Reference<style::XS // See if the existing style has any non-default properties. If so, reset them back to default. uno::Reference<beans::XPropertySet> xPropertySet(xStyle, uno::UNO_QUERY); uno::Reference<beans::XPropertySetInfo> xPropertySetInfo = xPropertySet->getPropertySetInfo(); - uno::Sequence<beans::Property> aProperties = xPropertySetInfo->getProperties(); + const uno::Sequence<beans::Property> aProperties = xPropertySetInfo->getProperties(); std::vector<OUString> aPropertyNames; aPropertyNames.reserve(aProperties.getLength()); std::transform(aProperties.begin(), aProperties.end(), std::back_inserter(aPropertyNames), |