diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2019-08-03 19:25:32 +0300 |
---|---|---|
committer | Arkadiy Illarionov <qarkai@gmail.com> | 2019-08-03 19:28:12 +0200 |
commit | 9307a23a40a0a18d86dade102354ba4871825c5a (patch) | |
tree | 162265ddb38b44f3e03d0b3d12626b71a3af29a6 /sc | |
parent | f59b2a66001272fc4d3350f7f9918fe0311c6f81 (diff) |
tdf#39593 extract getting max row length to template function
Change-Id: I23c81ac7dbd8785b12620aaf8ae2c090ae1785f8
Reviewed-on: https://gerrit.libreoffice.org/76894
Tested-by: Jenkins
Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/addincol.cxx | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx index 78104c11ef2e..7279aa4029ec 100644 --- a/sc/source/core/tool/addincol.cxx +++ b/sc/source/core/tool/addincol.cxx @@ -1463,6 +1463,18 @@ void ScUnoAddInCall::ExecuteCallWithArgs(uno::Sequence<uno::Any>& rCallArgs) } } +template <typename T> +static long lcl_GetMaxColCount(const uno::Sequence< uno::Sequence<T> >* pRowSeq) +{ + if (!pRowSeq->hasElements()) + return 0; + + auto pRow = std::max_element(pRowSeq->begin(), pRowSeq->end(), + [](const uno::Sequence<T>& a, const uno::Sequence<T>& b) { + return a.getLength() < b.getLength(); }); + return pRow->getLength(); +} + void ScUnoAddInCall::SetResult( const uno::Any& rNewRes ) { nErrCode = FormulaError::NONE; @@ -1528,16 +1540,10 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes ) if ( pRowSeq ) { long nRowCount = pRowSeq->getLength(); - const uno::Sequence<sal_Int32>* pRowArr = pRowSeq->getConstArray(); - long nMaxColCount = 0; - for (long nRow=0; nRow<nRowCount; nRow++) - { - long nTmp = pRowArr[nRow].getLength(); - if ( nTmp > nMaxColCount ) - nMaxColCount = nTmp; - } + long nMaxColCount = lcl_GetMaxColCount(pRowSeq); if ( nMaxColCount && nRowCount ) { + const uno::Sequence<sal_Int32>* pRowArr = pRowSeq->getConstArray(); xMatrix = new ScMatrix( static_cast<SCSIZE>(nMaxColCount), static_cast<SCSIZE>(nRowCount), 0.0); @@ -1569,16 +1575,10 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes ) if ( pRowSeq ) { long nRowCount = pRowSeq->getLength(); - const uno::Sequence<double>* pRowArr = pRowSeq->getConstArray(); - long nMaxColCount = 0; - for (long nRow=0; nRow<nRowCount; nRow++) - { - long nTmp = pRowArr[nRow].getLength(); - if ( nTmp > nMaxColCount ) - nMaxColCount = nTmp; - } + long nMaxColCount = lcl_GetMaxColCount(pRowSeq); if ( nMaxColCount && nRowCount ) { + const uno::Sequence<double>* pRowArr = pRowSeq->getConstArray(); xMatrix = new ScMatrix( static_cast<SCSIZE>(nMaxColCount), static_cast<SCSIZE>(nRowCount), 0.0); @@ -1610,16 +1610,10 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes ) if ( pRowSeq ) { long nRowCount = pRowSeq->getLength(); - const uno::Sequence<OUString>* pRowArr = pRowSeq->getConstArray(); - long nMaxColCount = 0; - for (long nRow=0; nRow<nRowCount; nRow++) - { - long nTmp = pRowArr[nRow].getLength(); - if ( nTmp > nMaxColCount ) - nMaxColCount = nTmp; - } + long nMaxColCount = lcl_GetMaxColCount(pRowSeq); if ( nMaxColCount && nRowCount ) { + const uno::Sequence<OUString>* pRowArr = pRowSeq->getConstArray(); xMatrix = new ScMatrix( static_cast<SCSIZE>(nMaxColCount), static_cast<SCSIZE>(nRowCount), 0.0); |