forked from mirror/go-json
Improve performance for decoding ( use switch-case )
This commit is contained in:
parent
2da797ecbb
commit
e14c0b6b66
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue