From edcdfe5477559ca6c62897f0cad47d4d6149d77a Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sat, 10 Aug 2019 19:07:30 +0300 Subject: Simplify Sequence iterations in postprocess..sax Use range-based loops, STL and comphelper functions Change-Id: If738d8f4e792c4686870183b0c0fdfbb61fd3351 Reviewed-on: https://gerrit.libreoffice.org/77245 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov --- pyuno/source/module/pyuno_adapter.cxx | 38 ++++++++++------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) (limited to 'pyuno') diff --git a/pyuno/source/module/pyuno_adapter.cxx b/pyuno/source/module/pyuno_adapter.cxx index f434b9ec2aed..1c392989d744 100644 --- a/pyuno/source/module/pyuno_adapter.cxx +++ b/pyuno/source/module/pyuno_adapter.cxx @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -137,33 +138,18 @@ Sequence< sal_Int16 > Adapter::getOutIndexes( const OUString & functionName ) "pyuno bridge: Couldn't get reflection for method " + functionName ); } - Sequence< ParamInfo > seqInfo = method->getParameterInfos(); - int i; - int nOuts = 0; - for( i = 0 ; i < seqInfo.getLength() ; i ++ ) + const Sequence< ParamInfo > seqInfo = method->getParameterInfos(); + std::vector retVec; + for( sal_Int32 i = 0; i < seqInfo.getLength(); ++i ) { if( seqInfo[i].aMode == css::reflection::ParamMode_OUT || seqInfo[i].aMode == css::reflection::ParamMode_INOUT ) { - // sequence must be interpreted as return value/outparameter tuple ! - nOuts ++; + retVec.push_back(static_cast(i)); } } - if( nOuts ) - { - ret.realloc( nOuts ); - sal_Int32 nOutsAssigned = 0; - for( i = 0 ; i < seqInfo.getLength() ; i ++ ) - { - if( seqInfo[i].aMode == css::reflection::ParamMode_OUT || - seqInfo[i].aMode == css::reflection::ParamMode_INOUT ) - { - ret[nOutsAssigned] = static_cast(i); - nOutsAssigned ++; - } - } - } + ret = comphelper::containerToSequence(retVec); } // guard active again ! m_methodOutIndexMap[ functionName ] = ret; @@ -276,24 +262,22 @@ Any Adapter::invoke( const OUString &aFunctionName, "pyuno bridge: Couldn't extract out parameters for method " + aFunctionName ); } - if( aOutParamIndex.getLength() +1 != seq.getLength() ) + auto nOutLength = aOutParamIndex.getLength(); + if( nOutLength + 1 != seq.getLength() ) { OUString sMsg = "pyuno bridge: expected for method " + aFunctionName + " one return value and " - + OUString::number(aOutParamIndex.getLength()) + + OUString::number(nOutLength) + " out parameters, got a sequence of " + OUString::number(seq.getLength()) + " elements as return value."; throw RuntimeException( sMsg, *this ); } - aOutParam.realloc( aOutParamIndex.getLength() ); + aOutParam.realloc( nOutLength ); ret = seq[0]; - for( i = 0 ; i < aOutParamIndex.getLength() ; i ++ ) - { - aOutParam[i] = seq[1+i]; - } + std::copy_n(std::next(seq.begin()), nOutLength, aOutParam.begin()); } // else { sequence is a return value !} } -- cgit