[Libreoffice-commits] core.git: sc/source

Eike Rathke erack at redhat.com
Fri Jul 6 12:25:34 UTC 2018


 sc/source/core/data/table1.cxx |   76 +++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 44 deletions(-)

New commits:
commit ec68d58afd53ffd5f0f524503dec607e52385c72
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Jul 6 12:15:35 2018 +0200

    GetNextPos: deduplicate some nMovX code
    
    Change-Id: I9208e2e0a9eaa27a81ffe1dd7054dffc7ddd75f4
    Reviewed-on: https://gerrit.libreoffice.org/57050
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 24e8d62a9b77..f68e8fff8e66 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1498,82 +1498,70 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCCOL nMovX, SCROW nMovY,
             const SCCOL nColCount = nEndCol - nStartCol + 1;
             std::unique_ptr<SCROW[]> pNextRows( new SCROW[nColCount]);
             const SCCOL nLastCol = aCol.size() - 1;
+            const bool bUp = (nMovX < 0);   // Moving left also means moving up in rows.
+            const SCROW nRowAdd = (bUp ? -1 : 1);
             sal_uInt16 nWrap = 0;
 
-            if ( nMovX > 0 )                            //  forward
+            for (SCCOL i = 0; i < nColCount; ++i)
+                pNextRows[i] = (i + nStartCol < nCol) ? (nRow + nRowAdd) : nRow;
+            do
             {
-                for (SCCOL i = 0; i < nColCount; ++i)
-                    pNextRows[i] = (i + nStartCol < nCol) ? (nRow+1) : nRow;
-                do
+                SCROW nNextRow = pNextRows[nCol - nStartCol] + nRowAdd;
+                if ( bMarked )
+                    nNextRow = rMark.GetNextMarked( nCol, nNextRow, bUp );
+                if ( bUnprotected )
+                    nNextRow = ( nCol <= nLastCol ) ? aCol[nCol].GetNextUnprotected( nNextRow, bUp ) :
+                        aDefaultColAttrArray.GetNextUnprotected( nNextRow, bUp );
+                pNextRows[nCol - nStartCol] = nNextRow;
+
+                if (bUp)
                 {
-                    SCROW nNextRow = pNextRows[nCol - nStartCol] + 1;
-                    if ( bMarked )
-                        nNextRow = rMark.GetNextMarked( nCol, nNextRow, false );
-                    if ( bUnprotected )
-                        nNextRow = ( nCol <= nLastCol ) ? aCol[nCol].GetNextUnprotected( nNextRow, false ) :
-                            aDefaultColAttrArray.GetNextUnprotected( nNextRow, false );
-                    pNextRows[nCol - nStartCol] = nNextRow;
-
-                    SCROW nMinRow = nEndRow + 1;
+                    SCROW nMaxRow = nStartRow - 1;
                     for (SCCOL i = 0; i < nColCount; ++i)
                     {
-                        if (pNextRows[i] < nMinRow)     // when two equal on the left
+                        if (pNextRows[i] >= nMaxRow)    // when two equal the right one
                         {
-                            nMinRow = pNextRows[i];
+                            nMaxRow = pNextRows[i];
                             nCol = i + nStartCol;
                         }
                     }
-                    nRow = nMinRow;
+                    nRow = nMaxRow;
 
-                    if ( nRow > nEndRow )
+                    if ( nRow < nStartRow )
                     {
                         if (++nWrap >= 2)
                             return;
-                        nCol = nStartCol;
-                        nRow = nStartRow;
+                        nCol = nEndCol;
+                        nRow = nEndRow;
                         for (SCCOL i = 0; i < nColCount; ++i)
-                            pNextRows[i] = nStartRow;   // do it all over again
+                            pNextRows[i] = nEndRow;     // do it all over again
                     }
                 }
-                while ( !ValidNextPos(nCol, nRow, rMark, bMarked, bUnprotected) );
-            }
-            else                                        //  backwards
-            {
-                for (SCCOL i = 0; i < nColCount; ++i)
-                    pNextRows[i] = (i + nStartCol > nCol) ? (nRow-1) : nRow;
-                do
+                else
                 {
-                    SCROW nNextRow = pNextRows[nCol - nStartCol] - 1;
-                    if ( bMarked )
-                        nNextRow = rMark.GetNextMarked( nCol, nNextRow, true );
-                    if ( bUnprotected )
-                        nNextRow = ( nCol <= nLastCol ) ? aCol[nCol].GetNextUnprotected( nNextRow, true ) :
-                            aDefaultColAttrArray.GetNextUnprotected( nNextRow, true );
-                    pNextRows[nCol - nStartCol] = nNextRow;
-
-                    SCROW nMaxRow = nStartRow - 1;
+                    SCROW nMinRow = nEndRow + 1;
                     for (SCCOL i = 0; i < nColCount; ++i)
                     {
-                        if (pNextRows[i] >= nMaxRow)    // when two equal on the right
+                        if (pNextRows[i] < nMinRow)     // when two equal the left one
                         {
-                            nMaxRow = pNextRows[i];
+                            nMinRow = pNextRows[i];
                             nCol = i + nStartCol;
                         }
                     }
-                    nRow = nMaxRow;
+                    nRow = nMinRow;
 
-                    if ( nRow < nStartRow )
+                    if ( nRow > nEndRow )
                     {
                         if (++nWrap >= 2)
                             return;
-                        nCol = nEndCol;
-                        nRow = nEndRow;
+                        nCol = nStartCol;
+                        nRow = nStartRow;
                         for (SCCOL i = 0; i < nColCount; ++i)
-                            pNextRows[i] = nEndRow;     // do it all over again
+                            pNextRows[i] = nStartRow;   // do it all over again
                     }
                 }
-                while ( !ValidNextPos(nCol, nRow, rMark, bMarked, bUnprotected) );
             }
+            while ( !ValidNextPos(nCol, nRow, rMark, bMarked, bUnprotected) );
         }
     }
 


More information about the Libreoffice-commits mailing list