summaryrefslogtreecommitdiff
path: root/excelize.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2019-11-10 16:51:15 +0800
committerGitHub <noreply@github.com>2019-11-10 16:51:15 +0800
commitc8c8397751e994dca05467e7615f6ee77704775b (patch)
tree023a4a3d98b0efcd38860a062f4fe26de81cbb81 /excelize.go
parent6abf8bf9723512086f009ca574bde1d6682fc83d (diff)
parentbf9a8355494eac18812f3caf6d469962824f627f (diff)
Fix #494 Merge pull request #514 from mlh758/fix-494-write-allocations
Reduce allocations when writing
Diffstat (limited to 'excelize.go')
-rw-r--r--excelize.go18
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
}