Skip to content

Commit a45bb76

Browse files
authored
Merge pull request #28 from goccy/feature/improve-performance
Refactor encodeEscapedString ( for improvement performance )
2 parents 12c1c98 + a9e3793 commit a45bb76

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

encode_string.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,21 @@ var hex = "0123456789abcdef"
219219

220220
func (e *Encoder) encodeEscapedString(s string) {
221221
valLen := len(s)
222-
e.buf = append(e.buf, '"')
223222
// write string, the fast path, without utf8 and escape support
224223
i := 0
225224
for ; i < valLen; i++ {
226225
c := s[i]
227-
if c < utf8.RuneSelf && htmlSafeSet[c] {
228-
e.buf = append(e.buf, c)
229-
} else {
226+
if c >= utf8.RuneSelf || !htmlSafeSet[c] {
230227
break
231228
}
232229
}
230+
e.buf = append(e.buf, '"')
233231
if i == valLen {
232+
e.buf = append(e.buf, s...)
234233
e.buf = append(e.buf, '"')
235234
return
236235
}
236+
e.buf = append(e.buf, s[:i]...)
237237
e.writeStringSlowPathWithHTMLEscaped(i, s, valLen)
238238
}
239239

0 commit comments

Comments
 (0)