diff options
| author | Harris <mike.harris@cerner.com> | 2019-10-28 10:34:21 -0500 |
|---|---|---|
| committer | Harris <mike.harris@cerner.com> | 2019-11-05 08:18:11 -0600 |
| commit | bf9a8355494eac18812f3caf6d469962824f627f (patch) | |
| tree | 023a4a3d98b0efcd38860a062f4fe26de81cbb81 /excelize.go | |
| parent | 6abf8bf9723512086f009ca574bde1d6682fc83d (diff) | |
Reduce allocations when writing
Fix #494
If a row is full, don't bother allocating a new one, just return it.
Use the last populated row as a hint for the size of new rows.
Simplify checkSheet to remove row map
Diffstat (limited to 'excelize.go')
| -rw-r--r-- | excelize.go | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/excelize.go b/excelize.go index 4d46b94..ba6445f 100644 --- a/excelize.go +++ b/excelize.go @@ -155,20 +155,12 @@ func checkSheet(xlsx *xlsxWorksheet) { row = lastRow } } - sheetData := xlsxSheetData{} - existsRows := map[int]int{} - for k := range xlsx.SheetData.Row { - existsRows[xlsx.SheetData.Row[k].R] = k + sheetData := xlsxSheetData{Row: make([]xlsxRow, row)} + for _, r := range xlsx.SheetData.Row { + sheetData.Row[r.R-1] = r } - for i := 0; i < row; i++ { - _, ok := existsRows[i+1] - if ok { - sheetData.Row = append(sheetData.Row, xlsx.SheetData.Row[existsRows[i+1]]) - } else { - sheetData.Row = append(sheetData.Row, xlsxRow{ - R: i + 1, - }) - } + for i := 1; i <= row; i++ { + sheetData.Row[i-1].R = i } xlsx.SheetData = sheetData } |
