Improve performance of skipWhiteSpace at decoding

This commit is contained in:
Masaaki Goshima 2020-04-30 19:08:50 +09:00
parent 0a48fecb1e
commit e50e1d4878
1 changed files with 12 additions and 2 deletions

View File

@ -1,5 +1,16 @@
package json
var (
isWhiteSpace = [256]bool{}
)
func init() {
isWhiteSpace[' '] = true
isWhiteSpace['\n'] = true
isWhiteSpace['\t'] = true
isWhiteSpace['\r'] = true
}
type context struct {
cursor int
buf []byte
@ -16,8 +27,7 @@ func (c *context) skipWhiteSpace() int {
buflen := c.buflen
buf := c.buf
for cursor := c.cursor; cursor < buflen; cursor++ {
switch buf[cursor] {
case ' ', '\n', '\t', '\r':
if isWhiteSpace[buf[cursor]] {
continue
}
c.cursor = cursor