From 4a1b4064568189d6f819f5fe19ff9bf6d6e8de95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 17 Nov 2017 12:56:58 +0100 Subject: CopySheet() using reflect instead of encoding/gob Use github.com/mohae/deepcopy to deep copy worksheets instead of the internal deepcopy function that was using encoding/gob serialization and deserialization. Rationale: 1/ using `encoding/gob` is much slower than [`mohae/deepcopy`](https://github.com/mohae/deepcopy/) 2/ When building an application this implementation of `deepcopy` drags the `encoding/gob` package into the binary. And this package is much bigger than `mohae/deepcopy` (which only depends on `time` and `reflect`). ``` $ LC_ALL=C stat -f "%6z %N" $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)/github.com/mohae/deepcopy.a $(go env GOROOT)/pkg/$(go env GOOS)_$(go env GOARCH)/encoding/gob.a 10508 .../pkg/darwin_amd64/github.com/mohae/deepcopy.a 541818 .../pkg/darwin_amd64/encoding/gob.a ``` --- lib.go | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'lib.go') diff --git a/lib.go b/lib.go index fc95b23..4379be4 100644 --- a/lib.go +++ b/lib.go @@ -3,7 +3,6 @@ package excelize import ( "archive/zip" "bytes" - "encoding/gob" "io" "log" "math" @@ -115,17 +114,6 @@ func intOnlyMapF(rune rune) rune { return -1 } -// deepCopy provides method to creates a deep copy of whatever is passed to it -// and returns the copy in an interface. The returned value will need to be -// asserted to the correct type. -func deepCopy(dst, src interface{}) error { - var buf bytes.Buffer - if err := gob.NewEncoder(&buf).Encode(src); err != nil { - return err - } - return gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst) -} - // boolPtr returns a pointer to a bool with the given value. func boolPtr(b bool) *bool { return &b } -- cgit v1.2.1