[Libreoffice-commits] core.git: sc/source
Arkadiy Illarionov (via logerrit)
logerrit at kemper.freedesktop.org
Sat Aug 3 17:29:16 UTC 2019
sc/source/core/tool/addincol.cxx | 42 ++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 24 deletions(-)
New commits:
commit 9307a23a40a0a18d86dade102354ba4871825c5a
Author: Arkadiy Illarionov <qarkai at gmail.com>
AuthorDate: Sat Aug 3 19:25:32 2019 +0300
Commit: Arkadiy Illarionov <qarkai at gmail.com>
CommitDate: Sat Aug 3 19:28:12 2019 +0200
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 at gmail.com>
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);
More information about the Libreoffice-commits
mailing list