Improve performance for stream decoding

This commit is contained in:
Masaaki Goshima 2020-07-31 22:38:43 +09:00
parent 83d55b8f1b
commit 0b40addc16
1 changed files with 11 additions and 6 deletions

View File

@ -90,10 +90,11 @@ func (s *stream) read() bool {
func (s *stream) skipWhiteSpace() { func (s *stream) skipWhiteSpace() {
LOOP: LOOP:
if isWhiteSpace[s.char()] { c := s.char()
if isWhiteSpace[c] {
s.cursor++ s.cursor++
goto LOOP goto LOOP
} else if s.char() == nul { } else if c == nul {
if s.read() { if s.read() {
goto LOOP goto LOOP
} }
@ -129,12 +130,14 @@ func (s *stream) skipValue() error {
case '"': case '"':
for { for {
s.cursor++ s.cursor++
if s.char() == nul { c := s.char()
if c == nul {
if !s.read() { if !s.read() {
return errUnexpectedEndOfJSON("value of string", s.totalOffset()) return errUnexpectedEndOfJSON("value of string", s.totalOffset())
} }
c = s.char()
} }
if s.char() != '"' { if c != '"' {
continue continue
} }
if s.prevChar() == '\\' { if s.prevChar() == '\\' {
@ -149,10 +152,12 @@ func (s *stream) skipValue() error {
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
for { for {
s.cursor++ s.cursor++
if floatTable[s.char()] { c := s.char()
if floatTable[c] {
continue continue
} else if s.char() == nul { } else if c == nul {
if s.read() { if s.read() {
s.cursor-- // for retry current character
continue continue
} }
} }