summaryrefslogtreecommitdiff
path: root/dbaccess
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 /dbaccess
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 'dbaccess')
-rw-r--r--dbaccess/source/core/dataaccess/ModelImpl.cxx2
-rw-r--r--dbaccess/source/core/dataaccess/connection.cxx2
-rw-r--r--dbaccess/source/core/dataaccess/databasedocument.cxx5
-rw-r--r--dbaccess/source/core/dataaccess/datasource.cxx10
-rw-r--r--dbaccess/source/ui/browser/unodatbr.cxx5
-rw-r--r--dbaccess/source/ui/misc/UITools.cxx8
-rw-r--r--dbaccess/source/ui/misc/dbsubcomponentcontroller.cxx5
-rw-r--r--dbaccess/source/ui/querydesign/querycontroller.cxx5
8 files changed, 24 insertions, 18 deletions
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx
index 8f993096fe95..c7a7238f3f97 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.cxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx
@@ -1376,7 +1376,7 @@ bool ODatabaseModelImpl::hasTrustedScriptingSignature(bool bAllowUIToAddAuthor)
uno::Reference<security::XDocumentDigitalSignatures> xSigner(
security::DocumentDigitalSignatures::createWithVersion(
comphelper::getProcessComponentContext(), aODFVersion));
- uno::Sequence<security::DocumentSignatureInformation> aInfo
+ const uno::Sequence<security::DocumentSignatureInformation> aInfo
= xSigner->verifyScriptingContentSignatures(xStorage,
uno::Reference<io::XInputStream>());
diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx
index d5889255523e..15054023170e 100644
--- a/dbaccess/source/core/dataaccess/connection.cxx
+++ b/dbaccess/source/core/dataaccess/connection.cxx
@@ -750,7 +750,7 @@ void OConnection::impl_checkTableQueryNames_nothrow()
try
{
Reference< XNameAccess > xTables( getTables() );
- Sequence< OUString > aTableNames( xTables->getElementNames() );
+ const Sequence< OUString > aTableNames( xTables->getElementNames() );
std::set< OUString > aSortedTableNames( aTableNames.begin(), aTableNames.end() );
Reference< XNameAccess > xQueries( getQueries() );
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index 7fc1cb6eb254..e9867def1b99 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -223,11 +223,12 @@ Sequence< Type > SAL_CALL ODatabaseDocument::getTypes( )
// allowed to contain macros, too.
if ( !m_bAllowDocumentScripting )
{
- auto newEnd = std::remove_if( aTypes.begin(), aTypes.end(),
+ auto [begin, end] = toNonConstRange(aTypes);
+ auto newEnd = std::remove_if( begin, end,
[](const Type& t)
{ return t == cppu::UnoType<XEmbeddedScripts>::get() ||
t == cppu::UnoType<XScriptInvocationContext>::get();} );
- aTypes.realloc( std::distance(aTypes.begin(), newEnd) );
+ aTypes.realloc( std::distance(begin, newEnd) );
}
return aTypes;
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx
index 4f499eccc263..48039c3e6943 100644
--- a/dbaccess/source/core/dataaccess/datasource.cxx
+++ b/dbaccess/source/core/dataaccess/datasource.cxx
@@ -1046,13 +1046,15 @@ void ODatabaseSource::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) con
// transform them so that only property values which fulfill certain
// criteria survive
Sequence< PropertyValue > aNonDefaultOrUserDefined( aValues.getLength() );
+ auto [begin, end] = toNonConstRange(aValues);
+ auto pCopyStart = aNonDefaultOrUserDefined.getArray();
const PropertyValue* pCopyEnd = std::remove_copy_if(
- aValues.begin(),
- aValues.end(),
- aNonDefaultOrUserDefined.getArray(),
+ begin,
+ end,
+ pCopyStart,
IsDefaultAndNotRemoveable( aPropertyAttributes )
);
- aNonDefaultOrUserDefined.realloc( pCopyEnd - aNonDefaultOrUserDefined.getArray() );
+ aNonDefaultOrUserDefined.realloc( pCopyEnd - pCopyStart );
rValue <<= aNonDefaultOrUserDefined;
}
catch( const Exception& )
diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx
index 43f084fec020..b6bf10274b8b 100644
--- a/dbaccess/source/ui/browser/unodatbr.cxx
+++ b/dbaccess/source/ui/browser/unodatbr.cxx
@@ -214,10 +214,11 @@ Sequence< Type > SAL_CALL SbaTableQueryBrowser::getTypes( )
OSL_PRECOND( !!m_aDocScriptSupport, "SbaTableQueryBrowser::getTypes: did not initialize this, yet!" );
if ( !m_aDocScriptSupport || !*m_aDocScriptSupport )
{
- auto newEnd = std::remove_if( aTypes.begin(), aTypes.end(),
+ auto [begin, end] = toNonConstRange(aTypes);
+ auto newEnd = std::remove_if( begin, end,
[](const Type& type)
{ return type == cppu::UnoType<XScriptInvocationContext>::get(); } );
- aTypes.realloc( std::distance(aTypes.begin(), newEnd) );
+ aTypes.realloc( std::distance(begin, newEnd) );
}
return aTypes;
}
diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx
index 4086e7b442f2..7c9a09cc8484 100644
--- a/dbaccess/source/ui/misc/UITools.cxx
+++ b/dbaccess/source/ui/misc/UITools.cxx
@@ -982,17 +982,17 @@ void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
_xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
// search the right propertyvalue
- const PropertyValue* pValue =std::find_if(aInfo.begin(), aInfo.end(),
+ const PropertyValue* pValue =std::find_if(std::cbegin(aInfo), std::cend(aInfo),
[](const PropertyValue& lhs)
{return lhs.Name == PROPERTY_AUTOINCREMENTCREATION;} );
- if ( pValue != aInfo.end() )
+ if ( pValue != std::cend(aInfo) )
pValue->Value >>= _rsAutoIncrementValue;
- pValue =std::find_if(aInfo.begin(), aInfo.end(),
+ pValue =std::find_if(std::cbegin(aInfo), std::cend(aInfo),
[](const PropertyValue& lhs)
{return lhs.Name == "IsAutoRetrievingEnabled";} );
- if ( pValue != aInfo.end() )
+ if ( pValue != std::cend(aInfo) )
pValue->Value >>= _rAutoIncrementValueEnabled;
}
diff --git a/dbaccess/source/ui/misc/dbsubcomponentcontroller.cxx b/dbaccess/source/ui/misc/dbsubcomponentcontroller.cxx
index 6a6784e92dcc..82ce80f71333 100644
--- a/dbaccess/source/ui/misc/dbsubcomponentcontroller.cxx
+++ b/dbaccess/source/ui/misc/dbsubcomponentcontroller.cxx
@@ -222,10 +222,11 @@ namespace dbaui
Sequence< Type > aTypes( DBSubComponentController_Base::getTypes() );
if ( !m_pImpl->documentHasScriptSupport() )
{
- auto newEnd = std::remove_if( aTypes.begin(), aTypes.end(),
+ auto [begin, end] = toNonConstRange(aTypes);
+ auto newEnd = std::remove_if( begin, end,
[](const Type& type)
{ return type == cppu::UnoType<XScriptInvocationContext>::get(); } );
- aTypes.realloc( std::distance(aTypes.begin(), newEnd) );
+ aTypes.realloc( std::distance(begin, newEnd) );
}
return aTypes;
}
diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx
index 8070df7a5f90..4f7bd55bde1e 100644
--- a/dbaccess/source/ui/querydesign/querycontroller.cxx
+++ b/dbaccess/source/ui/querydesign/querycontroller.cxx
@@ -288,9 +288,10 @@ void SAL_CALL OQueryController::getFastPropertyValue( Any& o_rValue, sal_Int32 i
PropertyAttribute::READONLY
);
+ auto [begin, end] = toNonConstRange(aProps);
std::sort(
- aProps.begin(),
- aProps.end(),
+ begin,
+ end,
::comphelper::PropertyCompareByName()
);