summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-10-13 09:02:48 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-14 06:00:49 +0200
commit8a017d25a62e878fdd32f189f0663b05d2ffb9cf (patch)
treec91ee53b5d9276ae30df785b52579a1b77a057df /sfx2
parent17d3cacfb9675268e709cfc95771ad4ce8bde75a (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 'sfx2')
-rw-r--r--sfx2/source/appl/appopen.cxx8
-rw-r--r--sfx2/source/appl/sfxhelp.cxx4
-rw-r--r--sfx2/source/control/charmapcontrol.cxx8
-rw-r--r--sfx2/source/devtools/ObjectInspectorTreeHandler.cxx2
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx2
-rw-r--r--sfx2/source/dialog/filtergrouping.cxx8
-rw-r--r--sfx2/source/dialog/mailmodel.cxx2
-rw-r--r--sfx2/source/doc/docfile.cxx6
-rw-r--r--sfx2/source/doc/docinsert.cxx2
-rw-r--r--sfx2/source/doc/guisaveas.cxx4
-rw-r--r--sfx2/source/doc/objmisc.cxx2
-rw-r--r--sfx2/source/doc/objserv.cxx2
-rw-r--r--sfx2/source/doc/objstor.cxx12
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx16
-rw-r--r--sfx2/source/sidebar/ResourceManager.cxx2
15 files changed, 41 insertions, 39 deletions
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index 5936accbfedb..4bae1c14a570 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -882,7 +882,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
Sequence < OUString > aTmp;
aRet >>= aTmp;
- aProtocols.insert(aProtocols.end(),aTmp.begin(),aTmp.end());
+ aProtocols.insert(aProtocols.end(),std::cbegin(aTmp),std::cend(aTmp));
}
}
@@ -1037,11 +1037,11 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
// Any Referer (that was relevant in the above call to
// SvtSecurityOptions::isSecureMacroUri) is no longer relevant, assuming
// this "open" request is initiated directly by the user:
- auto pArg = std::find_if(aArgs.begin(), aArgs.end(),
+ auto pArg = std::find_if(std::cbegin(aArgs), std::cend(aArgs),
[](const PropertyValue& rArg) { return rArg.Name == "Referer"; });
- if (pArg != aArgs.end())
+ if (pArg != std::cend(aArgs))
{
- auto nIndex = static_cast<sal_Int32>(std::distance(aArgs.begin(), pArg));
+ auto nIndex = static_cast<sal_Int32>(std::distance(std::cbegin(aArgs), pArg));
comphelper::removeElementAt(aArgs, nIndex);
}
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index 5f0b3f7f60ff..039b85bb1e27 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -473,9 +473,9 @@ OUString SfxHelp::GetHelpModuleName_Impl(std::u16string_view rHelpID)
ModuleManager::create(::comphelper::getProcessComponentContext()) );
Sequence< PropertyValue > lProps;
xModuleManager->getByName( aModuleIdentifier ) >>= lProps;
- auto pProp = std::find_if(lProps.begin(), lProps.end(),
+ auto pProp = std::find_if(std::cbegin(lProps), std::cend(lProps),
[](const PropertyValue& rProp) { return rProp.Name == "ooSetupFactoryShortName"; });
- if (pProp != lProps.end())
+ if (pProp != std::cend(lProps))
pProp->Value >>= aFactoryShortName;
}
catch (const Exception&)
diff --git a/sfx2/source/control/charmapcontrol.cxx b/sfx2/source/control/charmapcontrol.cxx
index b86cc52111ee..032306b8a85f 100644
--- a/sfx2/source/control/charmapcontrol.cxx
+++ b/sfx2/source/control/charmapcontrol.cxx
@@ -119,11 +119,11 @@ SfxCharmapCtrl::~SfxCharmapCtrl()
void SfxCharmapCtrl::getFavCharacterList()
{
//retrieve recent character list
- css::uno::Sequence< OUString > rFavCharList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterList::get() );
+ const css::uno::Sequence< OUString > rFavCharList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterList::get() );
m_aFavCharList.insert( m_aFavCharList.end(), rFavCharList.begin(), rFavCharList.end() );
//retrieve recent character font list
- css::uno::Sequence< OUString > rFavCharFontList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterFontList::get() );
+ const css::uno::Sequence< OUString > rFavCharFontList( officecfg::Office::Common::FavoriteCharacters::FavoriteCharacterFontList::get() );
m_aFavCharFontList.insert( m_aFavCharFontList.end(), rFavCharFontList.begin(), rFavCharFontList.end() );
// tdf#135997: make sure that the two lists are same length
@@ -158,11 +158,11 @@ void SfxCharmapCtrl::updateFavCharControl()
void SfxCharmapCtrl::getRecentCharacterList()
{
//retrieve recent character list
- css::uno::Sequence< OUString > rRecentCharList( officecfg::Office::Common::RecentCharacters::RecentCharacterList::get() );
+ const css::uno::Sequence< OUString > rRecentCharList( officecfg::Office::Common::RecentCharacters::RecentCharacterList::get() );
m_aRecentCharList.insert( m_aRecentCharList.end(), rRecentCharList.begin(), rRecentCharList.end() );
//retrieve recent character font list
- css::uno::Sequence< OUString > rRecentCharFontList( officecfg::Office::Common::RecentCharacters::RecentCharacterFontList::get() );
+ const css::uno::Sequence< OUString > rRecentCharFontList( officecfg::Office::Common::RecentCharacters::RecentCharacterFontList::get() );
m_aRecentCharFontList.insert( m_aRecentCharFontList.end(), rRecentCharFontList.begin(), rRecentCharFontList.end() );
// tdf#135997: make sure that the two lists are same length
diff --git a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
index 53f622554d62..253932bb2632 100644
--- a/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
+++ b/sfx2/source/devtools/ObjectInspectorTreeHandler.cxx
@@ -68,7 +68,7 @@ OUString enumValueToEnumName(uno::Any const& aValue,
xTypeDescription.set(xManager->getByHierarchicalName(aValue.getValueType().getTypeName()),
uno::UNO_QUERY);
- uno::Sequence<sal_Int32> aValues = xTypeDescription->getEnumValues();
+ const uno::Sequence<sal_Int32> aValues = xTypeDescription->getEnumValues();
sal_Int32 nValuesIndex = std::find(aValues.begin(), aValues.end(), nIntValue) - aValues.begin();
uno::Sequence<OUString> aNames = xTypeDescription->getEnumNames();
return aNames[nValuesIndex];
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 6bf8fc9b6036..1cede475db43 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -608,7 +608,7 @@ void FileDialogHelper_Impl::updateVersions()
if ( !xStorage.is() )
throw uno::RuntimeException();
- uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
+ const uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
aEntries.realloc( xVersions.getLength() + 1 );
aEntries[0] = SfxResId( STR_SFX_FILEDLG_ACTUALVERSION );
diff --git a/sfx2/source/dialog/filtergrouping.cxx b/sfx2/source/dialog/filtergrouping.cxx
index 86946325c8f9..aa2a8a930e8f 100644
--- a/sfx2/source/dialog/filtergrouping.cxx
+++ b/sfx2/source/dialog/filtergrouping.cxx
@@ -241,8 +241,8 @@ namespace sfx2
// are returned from the configuration - it is completely undefined, and we need a _defined_ order.
FilterClassReferrer aClassReferrer;
::std::for_each(
- aGlobalClasses.begin(),
- aGlobalClasses.end(),
+ std::cbegin(aGlobalClasses),
+ std::cend(aGlobalClasses),
CreateEmptyClassRememberPos( _rGlobalClasses, aClassReferrer )
);
// now _rGlobalClasses contains a dummy entry for each global class,
@@ -253,7 +253,7 @@ namespace sfx2
// go for all the single class entries
OConfigurationNode aFilterClassesNode =
_rFilterClassification.openNode( "GlobalFilters/Classes" );
- Sequence< OUString > aFilterClasses = aFilterClassesNode.getNodeNames();
+ const Sequence< OUString > aFilterClasses = aFilterClassesNode.getNodeNames();
::std::for_each(
aFilterClasses.begin(),
aFilterClasses.end(),
@@ -297,7 +297,7 @@ namespace sfx2
// the node for the local classes
OConfigurationNode aFilterClassesNode =
_rFilterClassification.openNode( "LocalFilters/Classes" );
- Sequence< OUString > aFilterClasses = aFilterClassesNode.getNodeNames();
+ const Sequence< OUString > aFilterClasses = aFilterClassesNode.getNodeNames();
::std::for_each(
aFilterClasses.begin(),
diff --git a/sfx2/source/dialog/mailmodel.cxx b/sfx2/source/dialog/mailmodel.cxx
index f361d92b858d..503efaae7ecf 100644
--- a/sfx2/source/dialog/mailmodel.cxx
+++ b/sfx2/source/dialog/mailmodel.cxx
@@ -175,7 +175,7 @@ SfxMailModel::SaveResult SfxMailModel::ShowFilterOptionsDialog(
if( xFilterDialog->execute() )
{
//get the filter data
- uno::Sequence< beans::PropertyValue > aPropsFromDialog = xFilterProperties->getPropertyValues();
+ const uno::Sequence< beans::PropertyValue > aPropsFromDialog = xFilterProperties->getPropertyValues();
//add them to the args
auto pProp = std::find_if(aPropsFromDialog.begin(), aPropsFromDialog.end(),
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 4e21ee41d1c6..43730796eb3e 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -3723,11 +3723,11 @@ void SfxMedium::RemoveVersion_Impl( const OUString& rName )
if ( !pImpl->aVersions.hasElements() )
return;
- auto pVersion = std::find_if(pImpl->aVersions.begin(), pImpl->aVersions.end(),
+ auto pVersion = std::find_if(std::cbegin(pImpl->aVersions), std::cend(pImpl->aVersions),
[&rName](const auto& rVersion) { return rVersion.Identifier == rName; });
- if (pVersion != pImpl->aVersions.end())
+ if (pVersion != std::cend(pImpl->aVersions))
{
- auto nIndex = static_cast<sal_Int32>(std::distance(pImpl->aVersions.begin(), pVersion));
+ auto nIndex = static_cast<sal_Int32>(std::distance(std::cbegin(pImpl->aVersions), pVersion));
comphelper::removeElementAt(pImpl->aVersions, nIndex);
}
}
diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx
index f9b757bac8ed..04fbea3cce7c 100644
--- a/sfx2/source/doc/docinsert.cxx
+++ b/sfx2/source/doc/docinsert.cxx
@@ -170,7 +170,7 @@ static void impl_FillURLList( sfx2::FileDialogHelper const * _pFileDlg, std::vec
{
DBG_ASSERT( _pFileDlg, "DocumentInserter::fillURLList(): invalid file dialog" );
- Sequence < OUString > aPathSeq = _pFileDlg->GetSelectedFiles();
+ const Sequence < OUString > aPathSeq = _pFileDlg->GetSelectedFiles();
if ( aPathSeq.hasElements() )
{
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index 57865df82b43..3a2b5a7b3da9 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -545,9 +545,9 @@ bool ModelData_Impl::ExecuteFilterDialog_Impl( const OUString& aFilterName )
uno::Any aAny = m_pOwner->GetFilterConfiguration()->getByName( aFilterName );
if ( aAny >>= 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 == "UIComponent"; });
- if (pProp != aProps.end())
+ if (pProp != std::cend(aProps))
{
OUString aServiceName;
pProp->Value >>= aServiceName;
diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 91e338413410..07d889a4f47b 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1807,7 +1807,7 @@ bool SfxObjectShell_Impl::hasTrustedScriptingSignature( bool bAllowUIToAddAuthor
|| nScriptingSignatureState == SignatureState::OK
|| nScriptingSignatureState == SignatureState::NOTVALIDATED )
{
- uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.GetDocumentSignatureInformation( true, xSigner );
+ const uno::Sequence< security::DocumentSignatureInformation > aInfo = rDocShell.GetDocumentSignatureInformation( true, xSigner );
if ( aInfo.hasElements() )
{
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 66f730af70b3..1182ad519d22 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -1297,7 +1297,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
{
bool bShow = false;
Reference< XCmisDocument > xCmisDoc( GetModel(), uno::UNO_QUERY );
- uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties( );
+ const uno::Sequence< document::CmisProperty> aCmisProperties = xCmisDoc->getCmisProperties( );
if ( xCmisDoc->isVersionable( ) && aCmisProperties.hasElements( ) )
{
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index e7c9001e5b49..3b8f347d7250 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -872,9 +872,9 @@ ErrCode SfxObjectShell::HandleFilter( SfxMedium* pMedium, SfxObjectShell const *
Any aAny = xFilterCFG->getByName( pFilter->GetName() );
if ( aAny >>= aProps )
{
- auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
[](const PropertyValue& rProp) { return rProp.Name == "UIComponent"; });
- if (pProp != aProps.end())
+ if (pProp != std::cend(aProps))
{
OUString aServiceName;
pProp->Value >>= aServiceName;
@@ -2179,9 +2179,9 @@ bool SfxObjectShell::ImportFrom(SfxMedium& rMedium,
}
OUString aFilterImplName;
- auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
[](const beans::PropertyValue& rFilterProp) { return rFilterProp.Name == "FilterService"; });
- if (pProp != aProps.end())
+ if (pProp != std::cend(aProps))
pProp->Value >>= aFilterImplName;
uno::Reference< document::XFilter > xLoader;
@@ -2358,9 +2358,9 @@ bool SfxObjectShell::ExportTo( SfxMedium& rMedium )
xFilters->getByName( aFilterName ) >>= aProps;
OUString aFilterImplName;
- auto pProp = std::find_if(aProps.begin(), aProps.end(),
+ auto pProp = std::find_if(std::cbegin(aProps), std::cend(aProps),
[](const beans::PropertyValue& rFilterProp) { return rFilterProp.Name == "FilterService"; });
- if (pProp != aProps.end())
+ if (pProp != std::cend(aProps))
pProp->Value >>= aFilterImplName;
if ( !aFilterImplName.isEmpty() )
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 75a5c732eecc..254ccec4e3c7 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -534,8 +534,8 @@ namespace
{
Sequence< uno::Type > aStrippedTypes( io_rTypes.getLength() - 1 );
::std::remove_copy_if(
- io_rTypes.begin(),
- io_rTypes.end(),
+ std::cbegin(io_rTypes),
+ std::cend(io_rTypes),
aStrippedTypes.getArray(),
[&i_rTypeToStrip](const uno::Type& aType) { return aType == i_rTypeToStrip; }
);
@@ -1026,7 +1026,7 @@ Sequence< beans::PropertyValue > SAL_CALL SfxBaseModel::getArgs2(const Sequence<
for ( const auto& rOrg : std::as_const(m_pData->m_seqArguments) )
{
- auto bNew = std::none_of(seqArgsOld.begin(), seqArgsOld.end(),
+ auto bNew = std::none_of(std::cbegin(seqArgsOld), std::cend(seqArgsOld),
[&rOrg](const beans::PropertyValue& rOld){ return rOld.Name == rOrg.Name; });
if ( bNew )
{
@@ -2792,9 +2792,10 @@ SfxMedium* SfxBaseModel::handleLoadError( ErrCode nError, SfxMedium* pMedium )
static void addTitle_Impl( Sequence < beans::PropertyValue >& rSeq, const OUString& rTitle )
{
- auto pProp = std::find_if(rSeq.begin(), rSeq.end(),
+ auto [begin, end] = toNonConstRange(rSeq);
+ auto pProp = std::find_if(begin, end,
[](const beans::PropertyValue& rProp) { return rProp.Name == "Title"; });
- if (pProp != rSeq.end())
+ if (pProp != end)
{
pProp->Value <<= rTitle;
}
@@ -2802,8 +2803,9 @@ static void addTitle_Impl( Sequence < beans::PropertyValue >& rSeq, const OUStri
{
sal_Int32 nCount = rSeq.getLength();
rSeq.realloc( nCount+1 );
- rSeq[nCount].Name = "Title";
- rSeq[nCount].Value <<= rTitle;
+ auto& el = rSeq[nCount];
+ el.Name = "Title";
+ el.Value <<= rTitle;
}
}
diff --git a/sfx2/source/sidebar/ResourceManager.cxx b/sfx2/source/sidebar/ResourceManager.cxx
index 6c3452e70fc3..51a48642586e 100644
--- a/sfx2/source/sidebar/ResourceManager.cxx
+++ b/sfx2/source/sidebar/ResourceManager.cxx
@@ -740,7 +740,7 @@ void ResourceManager::GetToolPanelNodeNames (
std::vector<OUString>& rMatchingNames,
const utl::OConfigurationTreeRoot& aRoot)
{
- Sequence<OUString> aChildNodeNames (aRoot.getNodeNames());
+ const Sequence<OUString> aChildNodeNames (aRoot.getNodeNames());
std::copy_if(aChildNodeNames.begin(), aChildNodeNames.end(), std::back_inserter(rMatchingNames),
[](const OUString& rChildNodeName) { return rChildNodeName.startsWith( "private:resource/toolpanel/" ); });
}