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 /sw/source/filter | |
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 'sw/source/filter')
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 20 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 16 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxsdrexport.cxx | 12 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxtablestyleexport.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 3 |
5 files changed, 28 insertions, 27 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 868196d654e0..f94baf8806a7 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -651,9 +651,9 @@ bool DocxAttributeOutput::TextBoxIsFramePr(const SwFrameFormat& rFrameFormat) { uno::Sequence< beans::PropertyValue > propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "ParaFrameProperties"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) aFrameProperties = pProp->Value; } bool bFrameProperties = false; @@ -2820,10 +2820,10 @@ void DocxAttributeOutput::GetSdtEndBefore(const SdrObject* pSdrObj) xPropSet->getPropertyValue("InteropGrabBag") >>= aGrabBag; } - auto pProp = std::find_if(aGrabBag.begin(), aGrabBag.end(), + auto pProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), [this](const beans::PropertyValue& rProp) { return "SdtEndBefore" == rProp.Name && m_bStartedCharSdt && !m_bEndCharSdt; }); - if (pProp != aGrabBag.end()) + if (pProp != std::cend(aGrabBag)) pProp->Value >>= m_bEndCharSdt; } @@ -4701,9 +4701,9 @@ void DocxAttributeOutput::LatentStyles() uno::Sequence<beans::PropertyValue> aInteropGrabBag; xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aLatentStyles; - auto pProp = std::find_if(aInteropGrabBag.begin(), aInteropGrabBag.end(), + auto pProp = std::find_if(std::cbegin(aInteropGrabBag), std::cend(aInteropGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "latentStyles"; }); - if (pProp != aInteropGrabBag.end()) + if (pProp != std::cend(aInteropGrabBag)) pProp->Value >>= aLatentStyles; if (!aLatentStyles.hasElements()) return; @@ -5736,9 +5736,9 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S uno::Reference< beans::XPropertySet > xPropSet( m_rExport.m_rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW ); uno::Sequence< beans::PropertyValue > aGrabBag, aObjectsInteropList,aObjectInteropAttributes; xPropSet->getPropertyValue( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) >>= aGrabBag; - auto pProp = std::find_if(aGrabBag.begin(), aGrabBag.end(), + auto pProp = std::find_if(std::cbegin(aGrabBag), std::cend(aGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "EmbeddedObjects"; }); - if (pProp != aGrabBag.end()) + if (pProp != std::cend(aGrabBag)) pProp->Value >>= aObjectsInteropList; SwOLEObj& aObject = rNode.GetOLEObj(); @@ -5757,9 +5757,9 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S default: SAL_WARN("sw.ww8", "DocxAttributeOutput::WriteOLE: invalid aspect value"); } - auto pObjectsInterop = std::find_if(aObjectsInteropList.begin(), aObjectsInteropList.end(), + auto pObjectsInterop = std::find_if(std::cbegin(aObjectsInteropList), std::cend(aObjectsInteropList), [&sObjectName](const beans::PropertyValue& rProp) { return rProp.Name == sObjectName; }); - if (pObjectsInterop != aObjectsInteropList.end()) + if (pObjectsInterop != std::cend(aObjectsInteropList)) pObjectsInterop->Value >>= aObjectInteropAttributes; for( const auto& rObjectInteropAttribute : std::as_const(aObjectInteropAttributes) ) diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index e4531e421796..b610adf30f7d 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -1369,9 +1369,9 @@ void DocxExport::WriteTheme() uno::Reference<xml::dom::XDocument> themeDom; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXTheme"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= themeDom; // no theme dom to write @@ -1472,14 +1472,14 @@ void DocxExport::WriteCustomXml() uno::Sequence<uno::Reference<xml::dom::XDocument> > customXmlDomPropslist; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXml"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= customXmlDomlist; - pProp = std::find_if(propList.begin(), propList.end(), + pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXCustomXmlProps"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= customXmlDomPropslist; for (sal_Int32 j = 0; j < customXmlDomlist.getLength(); j++) @@ -1589,9 +1589,9 @@ void DocxExport::WriteEmbeddings() uno::Sequence< beans::PropertyValue > embeddingsList; uno::Sequence< beans::PropertyValue > propList; xPropSet->getPropertyValue( aName ) >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "OOXEmbeddings"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= embeddingsList; for (const auto& rEmbedding : std::as_const(embeddingsList)) { diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index 1e1ac6bd66c3..ae5b7ca94fb1 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -83,7 +83,7 @@ OUString lclGetAnchorIdFromGrabBag(const SdrObject* pObj) aGrabBagName = "FrameInteropGrabBag"; else aGrabBagName = "InteropGrabBag"; - uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, aGrabBagName); + const uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, aGrabBagName); auto pProp = std::find_if(propList.begin(), propList.end(), [](const beans::PropertyValue& rProp) { return rProp.Name == "AnchorId"; }); @@ -1385,7 +1385,7 @@ void DocxSdrExport::writeVMLDrawing(const SdrObject* sdrObj, const SwFrameFormat static bool lcl_isLockedCanvas(const uno::Reference<drawing::XShape>& xShape) { - uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, "InteropGrabBag"); + const uno::Sequence<beans::PropertyValue> propList = lclGetProperty(xShape, "InteropGrabBag"); /* * Export as Locked Canvas only if the property * is in the PropertySet @@ -1835,11 +1835,11 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho { uno::Sequence<beans::PropertyValue> propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "mso-rotation-angle"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) aRotation = pProp->Value; } sal_Int32 nTmp; @@ -1867,11 +1867,11 @@ void DocxSdrExport::writeDMLTextFrame(ww8::Frame const* pParentFrame, int nAncho { uno::Sequence<beans::PropertyValue> propList; xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - auto pProp = std::find_if(propList.begin(), propList.end(), + auto pProp = std::find_if(std::cbegin(propList), std::cend(propList), [](const beans::PropertyValue& rProp) { return rProp.Name == "mso-orig-shape-type"; }); - if (pProp != propList.end()) + if (pProp != std::cend(propList)) pProp->Value >>= shapeType; } //Empty shapeType will lead to corruption so to avoid that shapeType is set to default i.e. "rect" diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx index 4ad89587eda1..570c43130778 100644 --- a/sw/source/filter/ww8/docxtablestyleexport.cxx +++ b/sw/source/filter/ww8/docxtablestyleexport.cxx @@ -130,9 +130,9 @@ void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite) xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aTableStyles; auto pProp = std::find_if( - aInteropGrabBag.begin(), aInteropGrabBag.end(), + std::cbegin(aInteropGrabBag), std::cend(aInteropGrabBag), [](const beans::PropertyValue& rProp) { return rProp.Name == "tableStyles"; }); - if (pProp != aInteropGrabBag.end()) + if (pProp != std::cend(aInteropGrabBag)) pProp->Value >>= aTableStyles; if (!aTableStyles.hasElements()) return; diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 0ba034aa6564..6e6ed96981f7 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -4253,7 +4253,8 @@ void WW8Export::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark ) { uno::Sequence< OUString > vListEntries; pListEntries->second >>= vListEntries; - copy(vListEntries.begin(), vListEntries.end(), back_inserter(aListItems)); + aListItems.reserve(vListEntries.getLength()); + copy(std::cbegin(vListEntries), std::cend(vListEntries), back_inserter(aListItems)); } } |