summaryrefslogtreecommitdiff
path: root/svl
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 /svl
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 'svl')
-rw-r--r--svl/source/config/asiancfg.cxx2
-rw-r--r--svl/source/numbers/zforlist.cxx26
-rw-r--r--svl/source/numbers/zformat.cxx2
-rw-r--r--svl/source/passwordcontainer/passwordcontainer.cxx2
-rw-r--r--svl/source/passwordcontainer/syscreds.cxx2
5 files changed, 17 insertions, 17 deletions
diff --git a/svl/source/config/asiancfg.cxx b/svl/source/config/asiancfg.cxx
index 43a6d19351c2..3e6affd8b83d 100644
--- a/svl/source/config/asiancfg.cxx
+++ b/svl/source/config/asiancfg.cxx
@@ -98,7 +98,7 @@ void SvxAsianConfig::SetCharDistanceCompression(CharCompressType value) {
css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales()
const
{
- css::uno::Sequence< OUString > ns(
+ const css::uno::Sequence< OUString > ns(
officecfg::Office::Common::AsianLayout::StartEndCharacters::get(
impl_->context)->
getElementNames());
diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx
index ed3499210e02..6b385f4e7854 100644
--- a/svl/source/numbers/zforlist.cxx
+++ b/svl/source/numbers/zforlist.cxx
@@ -2351,10 +2351,10 @@ sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex(
css::uno::Sequence< css::i18n::NumberFormatCode >& rSeq,
const NfIndexTableOffset nTabOff )
{
- auto pSeq = std::find_if(rSeq.begin(), rSeq.end(),
+ auto pSeq = std::find_if(std::cbegin(rSeq), std::cend(rSeq),
[nTabOff](const css::i18n::NumberFormatCode& rCode) { return rCode.Index == nTabOff; });
- if (pSeq != rSeq.end())
- return static_cast<sal_Int32>(std::distance(rSeq.begin(), pSeq));
+ if (pSeq != std::cend(rSeq))
+ return static_cast<sal_Int32>(std::distance(std::cbegin(rSeq), pSeq));
if (LocaleDataWrapper::areChecksEnabled() && (nTabOff < NF_CURRENCY_START
|| NF_CURRENCY_END < nTabOff || nTabOff == NF_CURRENCY_1000INT
|| nTabOff == NF_CURRENCY_1000INT_RED
@@ -2367,24 +2367,24 @@ sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex(
if ( rSeq.hasElements() )
{
// look for a preset default
- pSeq = std::find_if(rSeq.begin(), rSeq.end(),
+ pSeq = std::find_if(std::cbegin(rSeq), std::cend(rSeq),
[](const css::i18n::NumberFormatCode& rCode) { return rCode.Default; });
- if (pSeq != rSeq.end())
- return static_cast<sal_Int32>(std::distance(rSeq.begin(), pSeq));
+ if (pSeq != std::cend(rSeq))
+ return static_cast<sal_Int32>(std::distance(std::cbegin(rSeq), pSeq));
// currencies are special, not all format codes must exist, but all
// builtin number format key index positions must have a format assigned
if ( NF_CURRENCY_START <= nTabOff && nTabOff <= NF_CURRENCY_END )
{
// look for a format with decimals
- pSeq = std::find_if(rSeq.begin(), rSeq.end(),
+ pSeq = std::find_if(std::cbegin(rSeq), std::cend(rSeq),
[](const css::i18n::NumberFormatCode& rCode) { return rCode.Index == NF_CURRENCY_1000DEC2; });
- if (pSeq != rSeq.end())
- return static_cast<sal_Int32>(std::distance(rSeq.begin(), pSeq));
+ if (pSeq != std::cend(rSeq))
+ return static_cast<sal_Int32>(std::distance(std::cbegin(rSeq), pSeq));
// last resort: look for a format without decimals
- pSeq = std::find_if(rSeq.begin(), rSeq.end(),
+ pSeq = std::find_if(std::cbegin(rSeq), std::cend(rSeq),
[](const css::i18n::NumberFormatCode& rCode) { return rCode.Index == NF_CURRENCY_1000INT; });
- if (pSeq != rSeq.end())
- return static_cast<sal_Int32>(std::distance(rSeq.begin(), pSeq));
+ if (pSeq != std::cend(rSeq))
+ return static_cast<sal_Int32>(std::distance(std::cbegin(rSeq), pSeq));
}
}
else
@@ -4044,7 +4044,7 @@ const NfCurrencyEntry* SvNumberFormatter::GetCurrencyEntry( bool & bFoundBank,
void SvNumberFormatter::GetCompatibilityCurrency( OUString& rSymbol, OUString& rAbbrev ) const
{
::osl::MutexGuard aGuard( GetInstanceMutex() );
- css::uno::Sequence< css::i18n::Currency2 >
+ const css::uno::Sequence< css::i18n::Currency2 >
xCurrencies( xLocaleData->getAllCurrencies() );
auto pCurrency = std::find_if(xCurrencies.begin(), xCurrencies.end(),
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index c7364e4bc995..34e439ee4921 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -3405,7 +3405,7 @@ void SvNumberformat::SwitchToOtherCalendar( OUString& rOrgCalendar,
return;
using namespace ::com::sun::star::i18n;
- css::uno::Sequence< OUString > xCals = rCal.getAllCalendars(
+ const css::uno::Sequence< OUString > xCals = rCal.getAllCalendars(
rLoc().getLanguageTag().getLocale() );
sal_Int32 nCnt = xCals.getLength();
if ( nCnt <= 1 )
diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx
index cbe36add1bb2..c483a78b75cd 100644
--- a/svl/source/passwordcontainer/passwordcontainer.cxx
+++ b/svl/source/passwordcontainer/passwordcontainer.cxx
@@ -182,7 +182,7 @@ PasswordMap StorageItem::getInfo()
{
PasswordMap aResult;
- Sequence< OUString > aNodeNames = ConfigItem::GetNodeNames( "Store" );
+ const Sequence< OUString > aNodeNames = ConfigItem::GetNodeNames( "Store" );
sal_Int32 aNodeCount = aNodeNames.getLength();
Sequence< OUString > aPropNames( aNodeCount );
diff --git a/svl/source/passwordcontainer/syscreds.cxx b/svl/source/passwordcontainer/syscreds.cxx
index 156d4f0857a2..c4fb701ae8bc 100644
--- a/svl/source/passwordcontainer/syscreds.cxx
+++ b/svl/source/passwordcontainer/syscreds.cxx
@@ -169,7 +169,7 @@ void SysCredentialsConfig::initCfg()
osl::MutexGuard aGuard( m_aMutex );
if ( !m_bCfgInited )
{
- uno::Sequence< OUString > aURLs(
+ const uno::Sequence< OUString > aURLs(
m_aConfigItem.getSystemCredentialsURLs() );
m_aCfgContainer.insert( aURLs.begin(), aURLs.end() );
m_bCfgInited = true;