diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-14 09:25:24 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-15 10:36:36 +0200 |
commit | 2484de6728bd11bb7949003d112f1ece2223c7a1 (patch) | |
tree | 1296534e396da284b38d2c478dcd2b31c4714179 /unotools | |
parent | 88375fd36899d21d3309cf8333712e02a87d3a91 (diff) |
Remove non-const Sequence::begin()/end() in internal code
... to avoid hidden cost of multiple COW checks, because they
call getArray() internally.
This obsoletes [loplugin:sequenceloop].
Also rename toNonConstRange to asNonConstRange, to reflect that
the result is a view of the sequence, not an independent object.
TODO: also drop non-const operator[], but introduce operator[]
in SequenceRange.
Change-Id: Idd5fd7a3400fe65274d2a6343025e2ef8911635d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123518
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/source/config/cmdoptions.cxx | 2 | ||||
-rw-r--r-- | unotools/source/config/configitem.cxx | 6 | ||||
-rw-r--r-- | unotools/source/config/confignode.cxx | 2 | ||||
-rw-r--r-- | unotools/source/config/lingucfg.cxx | 2 | ||||
-rw-r--r-- | unotools/source/config/moduleoptions.cxx | 4 | ||||
-rw-r--r-- | unotools/source/config/viewoptions.cxx | 2 | ||||
-rw-r--r-- | unotools/source/i18n/localedatawrapper.cxx | 7 |
7 files changed, 13 insertions, 12 deletions
diff --git a/unotools/source/config/cmdoptions.cxx b/unotools/source/config/cmdoptions.cxx index ed1d45fb984d..631c3ddbfb1d 100644 --- a/unotools/source/config/cmdoptions.cxx +++ b/unotools/source/config/cmdoptions.cxx @@ -281,7 +281,7 @@ Sequence< OUString > SvtCommandOptions_Impl::impl_GetPropertyNames() Sequence< OUString > lDisabledItems = GetNodeNames( SETNODE_DISABLED, utl::ConfigNameFormat::LocalPath ); // Expand all keys - for (OUString& rItem : toNonConstRange(lDisabledItems)) + for (OUString& rItem : asNonConstRange(lDisabledItems)) rItem = SETNODE_DISABLED PATHDELIMITER + rItem + PATHDELIMITER PROPERTYNAME_CMD; // Return result. diff --git a/unotools/source/config/configitem.cxx b/unotools/source/config/configitem.cxx index cf0384ad3651..37a5cd4d8cb0 100644 --- a/unotools/source/config/configitem.cxx +++ b/unotools/source/config/configitem.cxx @@ -316,7 +316,7 @@ Sequence< sal_Bool > ConfigItem::GetReadOnlyStates(const css::uno::Sequence< OUS // We must be sure to return a valid information every time! // Set default to non readonly... similar to the configuration handling of this property. - std::fill_n(lStates.begin(), lStates.getLength(), false); + std::fill_n(lStates.getArray(), lStates.getLength(), false); // no access - no information... Reference< XHierarchicalNameAccess > xHierarchyAccess = GetTree(); @@ -655,7 +655,7 @@ static void lcl_normalizeLocalNames(Sequence< OUString >& _rNames, ConfigNameFor OUString sTypeName = xTypeContainer->getElementTemplateName(); sTypeName = sTypeName.copy(sTypeName.lastIndexOf('/')+1); - std::transform(std::cbegin(_rNames), std::cend(_rNames), _rNames.begin(), + std::transform(std::cbegin(_rNames), std::cend(_rNames), _rNames.getArray(), [&sTypeName](const OUString& rName) -> OUString { return wrapConfigurationElementName(rName,sTypeName); }); } else @@ -663,7 +663,7 @@ static void lcl_normalizeLocalNames(Sequence< OUString >& _rNames, ConfigNameFor Reference<XServiceInfo> xSVI(_xParentNode, UNO_QUERY); if (xSVI.is() && xSVI->supportsService("com.sun.star.configuration.SetAccess")) { - std::transform(std::cbegin(_rNames), std::cend(_rNames), _rNames.begin(), + std::transform(std::cbegin(_rNames), std::cend(_rNames), _rNames.getArray(), [](const OUString& rName) -> OUString { return wrapConfigurationElementName(rName); }); } } diff --git a/unotools/source/config/confignode.cxx b/unotools/source/config/confignode.cxx index f8bfb4c06418..b5669c7b485b 100644 --- a/unotools/source/config/confignode.cxx +++ b/unotools/source/config/confignode.cxx @@ -192,7 +192,7 @@ namespace utl { aReturn = m_xDirectAccess->getElementNames(); // normalize the names - std::transform(std::cbegin(aReturn), std::cend(aReturn), aReturn.begin(), + std::transform(std::cbegin(aReturn), std::cend(aReturn), aReturn.getArray(), [this](const OUString& rName) -> OUString { return normalizeName(rName, NO_CONFIGURATION); }); } catch(Exception&) diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx index 3b9232690fc2..b6d29f42fea4 100644 --- a/unotools/source/config/lingucfg.cxx +++ b/unotools/source/config/lingucfg.cxx @@ -976,7 +976,7 @@ bool SvtLinguConfig::GetDictionaryEntry( if (bSuccess) { // get file URL's for the locations - for (OUString& rLocation : aLocations) + for (OUString& rLocation : asNonConstRange(aLocations)) { if (!lcl_GetFileUrlFromOrigin( rLocation, rLocation )) bSuccess = false; diff --git a/unotools/source/config/moduleoptions.cxx b/unotools/source/config/moduleoptions.cxx index 26bdb65e4638..35018b8b88c7 100644 --- a/unotools/source/config/moduleoptions.cxx +++ b/unotools/source/config/moduleoptions.cxx @@ -364,7 +364,7 @@ void SvtModuleOptions_Impl::ImplCommit() sBasePath = PATHSEPARATOR + rInfo.getFactory() + PATHSEPARATOR; const css::uno::Sequence< css::beans::PropertyValue > lChangedProperties = rInfo.getChangedProperties ( sBasePath ); - std::copy(lChangedProperties.begin(), lChangedProperties.end(), std::next(lCommitProperties.begin(), nRealCount)); + std::copy(lChangedProperties.begin(), lChangedProperties.end(), std::next(lCommitProperties.getArray(), nRealCount)); nRealCount += lChangedProperties.getLength(); } // Resize commit list to real size. @@ -738,7 +738,7 @@ void SvtModuleOptions_Impl::MakeReadonlyStatesAvailable() return; css::uno::Sequence< OUString > lFactories = GetNodeNames(OUString()); - for (OUString& rFactory : toNonConstRange(lFactories)) + for (OUString& rFactory : asNonConstRange(lFactories)) rFactory += PATHSEPARATOR PROPERTYNAME_DEFAULTFILTER; css::uno::Sequence< sal_Bool > lReadonlyStates = GetReadOnlyStates(lFactories); diff --git a/unotools/source/config/viewoptions.cxx b/unotools/source/config/viewoptions.cxx index b20a45b4dbdc..4fff44a2051a 100644 --- a/unotools/source/config/viewoptions.cxx +++ b/unotools/source/config/viewoptions.cxx @@ -319,7 +319,7 @@ css::uno::Sequence< css::beans::NamedValue > SvtViewOptions::GetUserData() const sal_Int32 c = lNames.getLength(); css::uno::Sequence< css::beans::NamedValue > lUserData(c); - std::transform(lNames.begin(), lNames.end(), lUserData.begin(), + std::transform(lNames.begin(), lNames.end(), lUserData.getArray(), [&xUserData](const OUString& rName) -> css::beans::NamedValue { return { rName, xUserData->getByName(rName) }; }); diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx index 782ae724c6f4..b2417c3ee3ae 100644 --- a/unotools/source/i18n/localedatawrapper.cxx +++ b/unotools/source/i18n/localedatawrapper.cxx @@ -1563,15 +1563,16 @@ void LocaleDataWrapper::loadDateAcceptancePatterns( } // Never overwrite the locale's full date pattern! The first. - if (aDateAcceptancePatterns[0] == rPatterns[0]) + if (std::as_const(aDateAcceptancePatterns)[0] == rPatterns[0]) aDateAcceptancePatterns = comphelper::containerToSequence(rPatterns); // sane else { // Copy existing full date pattern and append the sequence passed. /* TODO: could check for duplicates and shrink target sequence */ Sequence< OUString > aTmp( rPatterns.size() + 1 ); - aTmp[0] = aDateAcceptancePatterns[0]; - std::copy(rPatterns.begin(), rPatterns.end(), std::next(aTmp.begin())); + auto it = aTmp.getArray(); + *it = std::as_const(aDateAcceptancePatterns)[0]; + std::copy(rPatterns.begin(), rPatterns.end(), std::next(it)); aDateAcceptancePatterns = aTmp; } } |