Reduce operation

This commit is contained in:
Masaaki Goshima 2021-02-06 01:19:24 +09:00
parent b3e93b7040
commit e0f5f9764f
1 changed files with 9 additions and 9 deletions

View File

@ -360,9 +360,9 @@ func (d *structDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) { func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
buflen := int64(len(buf)) buflen := int64(len(buf))
cursor = skipWhiteSpace(buf, cursor) cursor = skipWhiteSpace(buf, cursor)
switch buf[cursor] { b := (*sliceHeader)(unsafe.Pointer(&buf)).data
switch char(b, cursor) {
case 'n': case 'n':
buflen := int64(len(buf))
if cursor+3 >= buflen { if cursor+3 >= buflen {
return 0, errUnexpectedEndOfJSON("null", cursor) return 0, errUnexpectedEndOfJSON("null", cursor)
} }
@ -385,18 +385,17 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
return 0, errUnexpectedEndOfJSON("object", cursor) return 0, errUnexpectedEndOfJSON("object", cursor)
} }
cursor++ cursor++
for ; cursor < buflen; cursor++ { for {
c, field, err := d.keyDecoder(d, buf, cursor) c, field, err := d.keyDecoder(d, buf, cursor)
if err != nil { if err != nil {
return 0, err return 0, err
} }
cursor = c cursor = skipWhiteSpace(buf, c)
cursor = skipWhiteSpace(buf, cursor) if char(b, cursor) != ':' {
if buf[cursor] != ':' {
return 0, errExpected("colon after object key", cursor) return 0, errExpected("colon after object key", cursor)
} }
cursor++ cursor++
if cursor >= int64(len(buf)) { if cursor >= buflen {
return 0, errExpected("object value after colon", cursor) return 0, errExpected("object value after colon", cursor)
} }
if field != nil { if field != nil {
@ -413,13 +412,14 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
cursor = c cursor = c
} }
cursor = skipWhiteSpace(buf, cursor) cursor = skipWhiteSpace(buf, cursor)
if buf[cursor] == '}' { if char(b, cursor) == '}' {
cursor++ cursor++
return cursor, nil return cursor, nil
} }
if buf[cursor] != ',' { if char(b, cursor) != ',' {
return 0, errExpected("comma after object element", cursor) return 0, errExpected("comma after object element", cursor)
} }
cursor++
} }
return cursor, nil return cursor, nil
} }