Skip to content

Commit c936188

Browse files
authored
This closes #2029, use a faster deepcopy library (#2030)
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
1 parent 5f446f2 commit c936188

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

col.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"strconv"
1919
"strings"
2020

21-
"github.com/mohae/deepcopy"
21+
"github.com/tiendc/go-deepcopy"
2222
)
2323

2424
// Define the default cell size and EMU unit of measurement.
@@ -533,7 +533,8 @@ func (f *File) SetColWidth(sheet, startCol, endCol string, width float64) error
533533
func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol) []xlsxCol {
534534
var fc []xlsxCol
535535
for i := col.Min; i <= col.Max; i++ {
536-
c := deepcopy.Copy(col).(xlsxCol)
536+
var c xlsxCol
537+
deepcopy.Copy(&c, col)
537538
c.Min, c.Max = i, i
538539
fc = append(fc, c)
539540
}
@@ -551,7 +552,8 @@ func flatCols(col xlsxCol, cols []xlsxCol, replacer func(fc, c xlsxCol) xlsxCol)
551552
fc[idx] = replacer(fc[idx], column)
552553
continue
553554
}
554-
c := deepcopy.Copy(column).(xlsxCol)
555+
var c xlsxCol
556+
deepcopy.Copy(&c, column)
555557
c.Min, c.Max = i, i
556558
fc = append(fc, c)
557559
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/xuri/excelize/v2
33
go 1.18
44

55
require (
6-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
76
github.com/richardlehane/mscfb v1.0.4
8-
github.com/stretchr/testify v1.8.4
7+
github.com/stretchr/testify v1.9.0
8+
github.com/tiendc/go-deepcopy v1.1.0
99
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d
1010
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7
1111
golang.org/x/crypto v0.29.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
4-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
53
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
64
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
75
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
86
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
97
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
108
github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00=
119
github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
12-
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
13-
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
10+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
11+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
12+
github.com/tiendc/go-deepcopy v1.1.0 h1:rBHhm5vg7WYnGLwktbQouodWjBXDoStOL4S7v/K8S4A=
13+
github.com/tiendc/go-deepcopy v1.1.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
1414
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY=
1515
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
1616
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=

rows.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"strconv"
2121
"strings"
2222

23-
"github.com/mohae/deepcopy"
23+
"github.com/tiendc/go-deepcopy"
2424
)
2525

2626
// duplicateHelperFunc defines functions to duplicate helper.
@@ -653,7 +653,7 @@ func (f *File) DuplicateRowTo(sheet string, row, row2 int) error {
653653

654654
for i, r := range ws.SheetData.Row {
655655
if r.R == row {
656-
rowCopy = deepcopy.Copy(ws.SheetData.Row[i]).(xlsxRow)
656+
deepcopy.Copy(&rowCopy, ws.SheetData.Row[i])
657657
ok = true
658658
break
659659
}
@@ -729,7 +729,8 @@ func (f *File) duplicateConditionalFormat(ws *xlsxWorksheet, sheet string, row,
729729
}
730730
}
731731
if len(SQRef) > 0 {
732-
cfCopy := deepcopy.Copy(*cf).(xlsxConditionalFormatting)
732+
var cfCopy xlsxConditionalFormatting
733+
deepcopy.Copy(&cfCopy, *cf)
733734
cfCopy.SQRef = strings.Join(SQRef, " ")
734735
cfs = append(cfs, &cfCopy)
735736
}
@@ -759,7 +760,8 @@ func (f *File) duplicateDataValidations(ws *xlsxWorksheet, sheet string, row, ro
759760
}
760761
}
761762
if len(SQRef) > 0 {
762-
dvCopy := deepcopy.Copy(*dv).(xlsxDataValidation)
763+
var dvCopy xlsxDataValidation
764+
deepcopy.Copy(&dvCopy, *dv)
763765
dvCopy.Sqref = strings.Join(SQRef, " ")
764766
dvs = append(dvs, &dvCopy)
765767
}

sheet.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"unicode/utf16"
2828
"unicode/utf8"
2929

30-
"github.com/mohae/deepcopy"
30+
"github.com/tiendc/go-deepcopy"
3131
)
3232

3333
// NewSheet provides the function to create a new sheet by given a worksheet
@@ -124,7 +124,8 @@ func (f *File) mergeExpandedCols(ws *xlsxWorksheet) {
124124
Width: ws.Cols.Col[i-1].Width,
125125
}, ws.Cols.Col[i]); i++ {
126126
}
127-
column := deepcopy.Copy(ws.Cols.Col[left]).(xlsxCol)
127+
var column xlsxCol
128+
deepcopy.Copy(&column, ws.Cols.Col[left])
128129
if left < i-1 {
129130
column.Max = ws.Cols.Col[i-1].Min
130131
}
@@ -750,7 +751,8 @@ func (f *File) copySheet(from, to int) error {
750751
if err != nil {
751752
return err
752753
}
753-
worksheet := deepcopy.Copy(sheet).(*xlsxWorksheet)
754+
worksheet := &xlsxWorksheet{}
755+
deepcopy.Copy(worksheet, sheet)
754756
toSheetID := strconv.Itoa(f.getSheetID(f.GetSheetName(to)))
755757
sheetXMLPath := "xl/worksheets/sheet" + toSheetID + ".xml"
756758
if len(worksheet.SheetViews.SheetView) > 0 {

0 commit comments

Comments
 (0)