summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-10-28 15:57:38 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-28 20:09:19 +0200
commitc131f32fcfff1208adc38536839bc5168fcb7487 (patch)
tree15281689e85827f04af03349032f91196c3e7c29
parenta93329244a7d24b8a89d8f287b6123e56d13786d (diff)
Prepare for removal of non-const operator[] from Sequence in include
Change-Id: I85ca453f3add5ac5b59dc6f1ccb2cdb55f0a463c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124333 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--include/com/sun/star/uno/Sequence.hxx3
-rw-r--r--include/comphelper/sequence.hxx10
-rw-r--r--include/oox/helper/containerhelper.hxx3
-rw-r--r--include/toolkit/helper/macros.hxx2
-rw-r--r--include/vbahelper/vbahelperinterface.hxx7
5 files changed, 12 insertions, 13 deletions
diff --git a/include/com/sun/star/uno/Sequence.hxx b/include/com/sun/star/uno/Sequence.hxx
index 5356872b1378..73e51a9bc7f5 100644
--- a/include/com/sun/star/uno/Sequence.hxx
+++ b/include/com/sun/star/uno/Sequence.hxx
@@ -295,8 +295,9 @@ template <class E> inline auto asNonConstRange(css::uno::Sequence<E>& s)
// These allow to pass it as range-expression to range-based for loops
E* begin() { return std::pair<E*, E*>::first; }
E* end() { return std::pair<E*, E*>::second; }
+ E& operator[](sal_Int32 i) { assert(i >= 0 && i < end() - begin()); return begin()[i]; }
};
- return SequenceRange(s.getArray(), s.getLength());
+ return SequenceRange(s.getLength() ? s.getArray() : nullptr, s.getLength());
};
/// @endcond
diff --git a/include/comphelper/sequence.hxx b/include/comphelper/sequence.hxx
index ada6ee27b4ef..a42ef2d2f341 100644
--- a/include/comphelper/sequence.hxx
+++ b/include/comphelper/sequence.hxx
@@ -64,7 +64,8 @@ namespace comphelper
sal_Int32 n1 = left.getLength();
css::uno::Sequence<T> ret(n1 + right.getLength());
//TODO: check for overflow
- std::copy_n(left.getConstArray(), n1, ret.getArray());
+ auto pRet = ret.getArray();
+ std::copy_n(left.getConstArray(), n1, pRet);
sal_Int32 n2 = n1;
for (sal_Int32 i = 0; i != right.getLength(); ++i) {
bool found = false;
@@ -75,7 +76,7 @@ namespace comphelper
}
}
if (!found) {
- ret[n2++] = right[i];
+ pRet[n2++] = right[i];
}
}
ret.realloc(n2);
@@ -181,8 +182,9 @@ namespace comphelper
template < typename DstElementType, typename SrcType >
inline css::uno::Sequence< DstElementType > containerToSequence( const SrcType& i_Container )
{
- css::uno::Sequence< DstElementType > result( ::std::size(i_Container) );
- ::std::copy( ::std::begin(i_Container), ::std::end(i_Container), result.getArray() );
+ using ::std::size, ::std::begin, ::std::end;
+ css::uno::Sequence< DstElementType > result( size(i_Container) );
+ ::std::copy( begin(i_Container), end(i_Container), result.getArray() );
return result;
}
diff --git a/include/oox/helper/containerhelper.hxx b/include/oox/helper/containerhelper.hxx
index 256719c5334e..10af6995f52c 100644
--- a/include/oox/helper/containerhelper.hxx
+++ b/include/oox/helper/containerhelper.hxx
@@ -282,8 +282,9 @@ template< typename MatrixType >
if( !rMatrix.empty() )
{
aSeq.realloc( static_cast< sal_Int32 >( rMatrix.height() ) );
+ auto pSeq = aSeq.getArray();
for( size_t nRow = 0, nHeight = rMatrix.height(); nRow < nHeight; ++nRow )
- aSeq[ static_cast< sal_Int32 >( nRow ) ] =
+ pSeq[ static_cast< sal_Int32 >( nRow ) ] =
css::uno::Sequence< ValueType >( &rMatrix.row_front( nRow ), static_cast< sal_Int32 >( rMatrix.width() ) );
}
return aSeq;
diff --git a/include/toolkit/helper/macros.hxx b/include/toolkit/helper/macros.hxx
index cd121bc0998d..a04815ebaf20 100644
--- a/include/toolkit/helper/macros.hxx
+++ b/include/toolkit/helper/macros.hxx
@@ -149,7 +149,7 @@ IMPL_LISTENERMULTIPLEXER_LISTENERMETHOD_BODY( ClassName, InterfaceName, MethodNa
{ \
css::uno::Sequence< OUString > aNames = BaseClass::getSupportedServiceNames( ); \
aNames.realloc( aNames.getLength() + 1 ); \
- aNames[ aNames.getLength() - 1 ] = ServiceName; \
+ aNames.getArray()[ aNames.getLength() - 1 ] = ServiceName; \
return aNames; \
} \
diff --git a/include/vbahelper/vbahelperinterface.hxx b/include/vbahelper/vbahelperinterface.hxx
index 0bbf18992ec3..c7fb615b1f5a 100644
--- a/include/vbahelper/vbahelperinterface.hxx
+++ b/include/vbahelper/vbahelperinterface.hxx
@@ -132,12 +132,7 @@ OUString classname::getServiceImplName() \
} \
css::uno::Sequence< OUString > classname::getServiceNames() \
{ \
- static css::uno::Sequence< OUString > saServiceNames; \
- if( saServiceNames.getLength() == 0 ) \
- { \
- saServiceNames.realloc( 1 ); \
- saServiceNames[ 0 ] = servicename; \
- } \
+ static const css::uno::Sequence< OUString > saServiceNames { servicename }; \
return saServiceNames; \
}