diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-02-14 12:33:47 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-02-14 16:29:19 +0100 |
commit | 7adb3757944452a0f3a1a12fee1dd504eb90a1df (patch) | |
tree | dfb526e755ace05e5fbb77c471b8866a87480648 /sc | |
parent | 3d61c9026a8a562022fa3099472a82b60172f112 (diff) |
don't gradually move columns to a large distance (tdf#144380)
The old code was trying to move the changed columns, each one in
a loop, which is O(N^2). Since the changed columns are those that
are inserted/deleted (and thus the content shouldn't matter),
instead move all the columns after them to the right place,
which is O(N).
Change-Id: Iad29b945fe9b3525ece43523ba04ecf306797c6e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129911
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/data/table2.cxx | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 759a7858ec83..cde674b07360 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -305,9 +305,8 @@ void ScTable::InsertCol( if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow())) { - for (SCSIZE i=0; i < nSize; i++) - for (SCCOL nCol = aCol.size() - 1; nCol > nStartCol; nCol--) - aCol[nCol].SwapCol(aCol[nCol-1]); + for (SCCOL nCol = aCol.size() - 1 - nSize; nCol >= nStartCol; --nCol) + aCol[nCol].SwapCol(aCol[nCol+nSize]); } else { @@ -390,9 +389,8 @@ void ScTable::DeleteCol( if ((nStartRow == 0) && (nEndRow == rDocument.MaxRow())) { - for (SCSIZE i=0; i < nSize; i++) - for (SCCOL nCol = nStartCol; nCol < aCol.size() - 1; nCol++) - aCol[nCol].SwapCol(aCol[nCol+1]); + for (SCCOL nCol = nStartCol + nSize; nCol < aCol.size(); ++nCol) + aCol[nCol].SwapCol(aCol[nCol - nSize]); } else { |