From 8713c81e85228efa6551e7d2dbd1b96659c9b8d8 Mon Sep 17 00:00:00 2001 From: akondratev Date: Wed, 13 Sep 2023 19:32:31 +0300 Subject: [PATCH] fix(CharsetToUTF8): use strings.Builder --- internal/cp/charset.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/cp/charset.go b/internal/cp/charset.go index 8dc2279e..55155d94 100644 --- a/internal/cp/charset.go +++ b/internal/cp/charset.go @@ -1,5 +1,9 @@ package cp +import ( + "strings" +) + type charsetMap struct { sb [256]rune // single byte runes, -1 for a double byte character lead byte db map[int]rune // double byte runes @@ -91,7 +95,9 @@ func CharsetToUTF8(col Collation, s []byte) string { if cm == nil { return string(s) } - buf := make([]rune, 0, len(s)) + + buf := strings.Builder{} + buf.Grow(len(s)) for i := 0; i < len(s); i++ { ch := cm.sb[s[i]] if ch == -1 { @@ -107,7 +113,7 @@ func CharsetToUTF8(col Collation, s []byte) string { } } } - buf = append(buf, ch) + buf.WriteRune(ch) } - return string(buf) + return buf.String() }