summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-10-14 09:25:24 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-15 10:36:36 +0200
commit2484de6728bd11bb7949003d112f1ece2223c7a1 (patch)
tree1296534e396da284b38d2c478dcd2b31c4714179 /comphelper
parent88375fd36899d21d3309cf8333712e02a87d3a91 (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 'comphelper')
-rw-r--r--comphelper/source/property/opropertybag.cxx2
-rw-r--r--comphelper/source/property/property.cxx18
-rw-r--r--comphelper/source/property/propertycontainerhelper.cxx2
3 files changed, 8 insertions, 14 deletions
diff --git a/comphelper/source/property/opropertybag.cxx b/comphelper/source/property/opropertybag.cxx
index f84d509847eb..e0b389c19199 100644
--- a/comphelper/source/property/opropertybag.cxx
+++ b/comphelper/source/property/opropertybag.cxx
@@ -425,7 +425,7 @@ namespace comphelper
{
// sort (the XMultiPropertySet interface requires this)
Sequence< PropertyValue > aProperties( _rProps );
- auto [begin, end] = toNonConstRange(aProperties);
+ auto [begin, end] = asNonConstRange(aProperties);
std::sort(
begin,
end,
diff --git a/comphelper/source/property/property.cxx b/comphelper/source/property/property.cxx
index 75208c2c51b4..49a7a108f09a 100644
--- a/comphelper/source/property/property.cxx
+++ b/comphelper/source/property/property.cxx
@@ -138,31 +138,25 @@ bool hasProperty(const OUString& _rName, const Reference<XPropertySet>& _rxSet)
void RemoveProperty(Sequence<Property>& _rProps, const OUString& _rPropName)
{
- sal_Int32 nLen = _rProps.getLength();
-
// binary search
- const Property* pProperties = _rProps.getConstArray();
Property aNameProp(_rPropName, 0, Type(), 0);
- const Property* pResult = std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName());
+ const Property* pResult = std::lower_bound(std::cbegin(_rProps), std::cend(_rProps), aNameProp, PropertyCompareByName());
- if ( pResult != _rProps.end() && pResult->Name == _rPropName )
+ if ( pResult != std::cend(_rProps) && pResult->Name == _rPropName)
{
- OSL_ENSURE(pResult->Name == _rPropName, "::RemoveProperty Properties not sorted");
- removeElementAt(_rProps, pResult - pProperties);
+ removeElementAt(_rProps, pResult - std::cbegin(_rProps));
}
}
void ModifyPropertyAttributes(Sequence<Property>& seqProps, const OUString& sPropName, sal_Int16 nAddAttrib, sal_Int16 nRemoveAttrib)
{
- sal_Int32 nLen = seqProps.getLength();
-
// binary search
- Property* pProperties = seqProps.getArray();
+ auto [begin, end] = asNonConstRange(seqProps);
Property aNameProp(sPropName, 0, Type(), 0);
- Property* pResult = std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName());
+ Property* pResult = std::lower_bound(begin, end, aNameProp, PropertyCompareByName());
- if ( (pResult != seqProps.end()) && (pResult->Name == sPropName) )
+ if ( (pResult != end) && (pResult->Name == sPropName) )
{
pResult->Attributes |= nAddAttrib;
pResult->Attributes &= ~nRemoveAttrib;
diff --git a/comphelper/source/property/propertycontainerhelper.cxx b/comphelper/source/property/propertycontainerhelper.cxx
index 73dcbd2e862b..5fd6053ce100 100644
--- a/comphelper/source/property/propertycontainerhelper.cxx
+++ b/comphelper/source/property/propertycontainerhelper.cxx
@@ -469,7 +469,7 @@ void OPropertyContainerHelper::describeProperties(Sequence< Property >& _rProps)
}
// as our property vector is sorted by handles, not by name, we have to sort aOwnProps
- auto [begin, end] = toNonConstRange(aOwnProps);
+ auto [begin, end] = asNonConstRange(aOwnProps);
std::sort(begin, end, PropertyCompareByName());
// unfortunately the STL merge function does not allow the output range to overlap one of the input ranges,