From 2f8c9089adf1c6e002ad16f6336acc661d8679b4 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Tue, 30 Sep 2014 22:18:46 +0000 Subject: [PATCH] fpspreadsheet: Fix speed issues in saving large files due to unnecessary calculation of col/row limits. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3615 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/fpspreadsheet/fpsopendocument.pas | 3 ++- components/fpspreadsheet/fpspreadsheet.pas | 27 +++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 0bc45e38c..be8792366 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -2988,6 +2988,7 @@ begin // Now loop through all rows r := firstRow; while (r <= lastRow) do begin + rowsRepeated := 1; // Look for the row style of the current row (r) row := ASheet.FindRow(r); if row = nil then @@ -3100,7 +3101,7 @@ begin // Next row inc(r, rowsRepeated); - rowsRepeated := 1; +// rowsRepeated := 1; end; end; diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas index e7d06c377..97f80b4ea 100755 --- a/components/fpspreadsheet/fpspreadsheet.pas +++ b/components/fpspreadsheet/fpspreadsheet.pas @@ -2917,6 +2917,7 @@ var r, c: Cardinal; cell: PCell; base: PCell; + lastCol, lastRow: Cardinal; begin base := FindSharedFormulaBase(ACell); if base = nil then begin @@ -2928,15 +2929,17 @@ begin ARow2 := ARow1; ACol1 := base^.Col; ACol2 := ACol1; + lastCol := GetLastOccupiedColIndex; + lastRow := GetLastOccupiedRowIndex; // ... and go along first COLUMN to find the end of the shared formula block, ... - for c := ACol1+1 to GetLastOccupiedColIndex do + for c := ACol1+1 to lastCol do begin cell := FindCell(ARow1, c); if (cell <> nil) and (cell^.SharedFormulaBase = base) then ACol2 := c; end; // ... and go along first ROW to find the end of the shared formula block - for r := ARow1 + 1 to GetLastOccupiedRowIndex do + for r := ARow1 + 1 to lastRow do begin cell := FindCell(r, ACol1); if (cell <> nil) and (cell^.SharedFormulaBase = base) then @@ -2955,9 +2958,14 @@ procedure TsWorksheet.FixSharedFormulas; var r,c, r1,c1, r2,c2: Cardinal; cell: PCell; + firstRow, firstCol, lastRow, lastCol: Cardinal; begin - for r := GetFirstRowIndex to GetLastOccupiedRowIndex do - for c := GetFirstColIndex to GetlastOccupiedColIndex do + firstRow := GetFirstRowIndex; + firstCol := GetFirstColIndex; + lastRow := GetLastOccupiedRowIndex; + lastCol := GetLastOccupiedColIndex; + for r := firstRow to lastRow do + for c := firstCol to lastCol do begin cell := FindCell(r, c); if FindSharedFormulaRange(cell, r1, c1, r2, c2) and (r1 = r2) and (c1 = c2) then @@ -2976,13 +2984,18 @@ var cell: PCell; rng: TsCellRange; n: Integer; + firstRow, firstCol, lastRow, lastCol: Cardinal; begin + firstRow := GetFirstRowIndex; + lastRow := GetLastOccupiedRowIndex; + firstCol := GetFirstColIndex; + lastCol := GetLastOccupiedColIndex; n := 0; SetLength(AList, n); - for r := GetFirstRowIndex to GetLastOccupiedRowIndex do + for r := firstRow to lastRow do begin - c := GetFirstColIndex; - while (c <= GetLastOccupiedColIndex) do + c := firstCol; + while (c <= lastCol) do begin cell := FindCell(r, c); if IsMergeBase(cell) then