Skip to content

Commit

Permalink
Reduce operation
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Feb 5, 2021
1 parent b3e93b7 commit e0f5f97
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions decode_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
buflen := int64(len(buf))
cursor = skipWhiteSpace(buf, cursor)
switch buf[cursor] {
b := (*sliceHeader)(unsafe.Pointer(&buf)).data
switch char(b, cursor) {
case 'n':
buflen := int64(len(buf))
if cursor+3 >= buflen {
return 0, errUnexpectedEndOfJSON("null", cursor)
}
Expand All @@ -385,18 +385,17 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
return 0, errUnexpectedEndOfJSON("object", cursor)
}
cursor++
for ; cursor < buflen; cursor++ {
for {
c, field, err := d.keyDecoder(d, buf, cursor)
if err != nil {
return 0, err
}
cursor = c
cursor = skipWhiteSpace(buf, cursor)
if buf[cursor] != ':' {
cursor = skipWhiteSpace(buf, c)
if char(b, cursor) != ':' {
return 0, errExpected("colon after object key", cursor)
}
cursor++
if cursor >= int64(len(buf)) {
if cursor >= buflen {
return 0, errExpected("object value after colon", cursor)
}
if field != nil {
Expand All @@ -413,13 +412,14 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
cursor = c
}
cursor = skipWhiteSpace(buf, cursor)
if buf[cursor] == '}' {
if char(b, cursor) == '}' {
cursor++
return cursor, nil
}
if buf[cursor] != ',' {
if char(b, cursor) != ',' {
return 0, errExpected("comma after object element", cursor)
}
cursor++
}
return cursor, nil
}

0 comments on commit e0f5f97

Please sign in to comment.