Improve performance for decoding ( use switch-case )

This commit is contained in:
Masaaki Goshima 2020-05-05 19:18:28 +09:00
parent 2da797ecbb
commit e14c0b6b66
2 changed files with 8 additions and 11 deletions

View File

@ -33,12 +33,10 @@ func (d *stringDecoder) decodeByte(ctx *context) ([]byte, error) {
cursor++
start := cursor
for ; cursor < buflen; cursor++ {
tk := buf[cursor]
if tk == '\\' {
switch buf[cursor] {
case '\\':
cursor++
continue
}
if tk == '"' {
case '"':
literal := buf[start:cursor]
cursor++
ctx.cursor = cursor

View File

@ -51,19 +51,18 @@ func (d *structDecoder) skipValue(ctx *context) error {
case '"':
cursor++
for ; cursor < buflen; cursor++ {
tk := buf[cursor]
if tk == '\\' {
switch buf[cursor] {
case '\\':
cursor++
continue
}
if tk == '"' {
case '"':
if bracketCount == 0 && braceCount == 0 {
ctx.cursor = cursor + 1
return nil
}
break
goto QUOTE_END
}
}
QUOTE_END:
}
}
return errors.New("unexpected error value")