Skip to content

Commit

Permalink
fix(CharsetToUTF8): use strings.Builder (#154)
Browse files Browse the repository at this point in the history
Co-authored-by: akondratev <artem.kondratev@goods.ru>
  • Loading branch information
konart and akondratev committed Sep 14, 2023
1 parent 80cf4b6 commit d3f844a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/cp/charset.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -107,7 +113,7 @@ func CharsetToUTF8(col Collation, s []byte) string {
}
}
}
buf = append(buf, ch)
buf.WriteRune(ch)
}
return string(buf)
return buf.String()
}

0 comments on commit d3f844a

Please sign in to comment.