mirror of https://github.com/goccy/go-json.git
Merge pull request #28 from goccy/feature/improve-performance
Refactor encodeEscapedString ( for improvement performance )
This commit is contained in:
commit
a45bb76d99
|
@ -219,21 +219,21 @@ var hex = "0123456789abcdef"
|
||||||
|
|
||||||
func (e *Encoder) encodeEscapedString(s string) {
|
func (e *Encoder) encodeEscapedString(s string) {
|
||||||
valLen := len(s)
|
valLen := len(s)
|
||||||
e.buf = append(e.buf, '"')
|
|
||||||
// write string, the fast path, without utf8 and escape support
|
// write string, the fast path, without utf8 and escape support
|
||||||
i := 0
|
i := 0
|
||||||
for ; i < valLen; i++ {
|
for ; i < valLen; i++ {
|
||||||
c := s[i]
|
c := s[i]
|
||||||
if c < utf8.RuneSelf && htmlSafeSet[c] {
|
if c >= utf8.RuneSelf || !htmlSafeSet[c] {
|
||||||
e.buf = append(e.buf, c)
|
|
||||||
} else {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
e.buf = append(e.buf, '"')
|
||||||
if i == valLen {
|
if i == valLen {
|
||||||
|
e.buf = append(e.buf, s...)
|
||||||
e.buf = append(e.buf, '"')
|
e.buf = append(e.buf, '"')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
e.buf = append(e.buf, s[:i]...)
|
||||||
e.writeStringSlowPathWithHTMLEscaped(i, s, valLen)
|
e.writeStringSlowPathWithHTMLEscaped(i, s, valLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue