From d96440edc480976e3ec48958c68e67f7a506ad32 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 15 May 2018 21:00:56 +0800 Subject: - Performance optimization 20% faster, 14% memory savings on set cell values; - Using the canonical syntax in issue template and contributing guide; - go test has been updated --- sheet.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'sheet.go') diff --git a/sheet.go b/sheet.go index 10a0fdb..cb3bba2 100644 --- a/sheet.go +++ b/sheet.go @@ -94,13 +94,15 @@ func (f *File) worksheetWriter() { // trimCell provides function to trim blank cells which created by completeCol. func trimCell(column []xlsxC) []xlsxC { - col := []xlsxC{} + col := make([]xlsxC, len(column)) + i := 0 for _, c := range column { if c.S != 0 || c.V != "" || c.F != nil || c.T != "" { - col = append(col, c) + col[i] = c + i++ } } - return col + return col[0:i] } // Read and update property of contents type of XLSX. @@ -641,8 +643,16 @@ func (f *File) GetSheetVisible(name string) bool { // trimSheetName provides function to trim invaild characters by given worksheet // name. func trimSheetName(name string) string { - r := strings.NewReplacer(":", "", "\\", "", "/", "", "?", "", "*", "", "[", "", "]", "") - name = r.Replace(name) + r := []rune{} + for _, v := range []rune(name) { + switch v { + case 58, 92, 47, 63, 42, 91, 93: // replace :\/?*[] + continue + default: + r = append(r, v) + } + } + name = string(r) if utf8.RuneCountInString(name) > 31 { name = string([]rune(name)[0:31]) } -- cgit v1.2.1