Skip to content

Commit 91d36cc

Browse files
Fix performance regression in v2.9.0, reduce trim cell value memory allocation for blank cells (qax-os#2100)
1 parent e9d27c7 commit 91d36cc

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

cell.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
package excelize
1313

1414
import (
15-
"bytes"
1615
"encoding/xml"
1716
"fmt"
1817
"math"
@@ -510,13 +509,6 @@ func trimCellValue(value string, escape bool) (v string, ns xml.Attr) {
510509
if utf8.RuneCountInString(value) > TotalCellChars {
511510
value = string([]rune(value)[:TotalCellChars])
512511
}
513-
if escape && value != "" {
514-
var buf bytes.Buffer
515-
enc := xml.NewEncoder(&buf)
516-
_ = enc.EncodeToken(xml.CharData(value))
517-
_ = enc.Flush()
518-
value = buf.String()
519-
}
520512
if value != "" {
521513
prefix, suffix := value[0], value[len(value)-1]
522514
for _, ascii := range []byte{9, 10, 13, 32} {
@@ -528,6 +520,12 @@ func trimCellValue(value string, escape bool) (v string, ns xml.Attr) {
528520
break
529521
}
530522
}
523+
524+
if escape {
525+
var buf strings.Builder
526+
_ = xml.EscapeText(&buf, []byte(value))
527+
value = strings.ReplaceAll(buf.String(), "
", "\n")
528+
}
531529
}
532530
v = bstrMarshal(value)
533531
return

0 commit comments

Comments
 (0)