forked from mirror/go-json
Compare commits
1 Commits
master
...
feature/bc
Author | SHA1 | Date |
---|---|---|
Masaaki Goshima | c7de009abf |
|
@ -15,7 +15,7 @@ func (d Delim) String() string {
|
|||
}
|
||||
|
||||
type decoder interface {
|
||||
decode([]byte, int64, unsafe.Pointer) (int64, error)
|
||||
decode(*sliceHeader, int64, unsafe.Pointer) (int64, error)
|
||||
decodeStream(*stream, unsafe.Pointer) error
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,8 @@ func (d *Decoder) decode(src []byte, header *interfaceHeader) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := dec.decode(src, 0, header.ptr); err != nil {
|
||||
b := (*sliceHeader)(unsafe.Pointer(&src))
|
||||
if _, err := dec.decode(b, 0, header.ptr); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -26,7 +26,7 @@ func (d *anonymousFieldDecoder) decodeStream(s *stream, p unsafe.Pointer) error
|
|||
return d.dec.decodeStream(s, unsafe.Pointer(uintptr(p)+d.offset))
|
||||
}
|
||||
|
||||
func (d *anonymousFieldDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *anonymousFieldDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
if *(*unsafe.Pointer)(p) == nil {
|
||||
*(*unsafe.Pointer)(p) = unsafe_New(d.structType)
|
||||
}
|
||||
|
|
|
@ -76,25 +76,24 @@ ERROR:
|
|||
return errUnexpectedEndOfJSON("array", s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(len(buf))
|
||||
func (d *arrayDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(buf.len)
|
||||
for ; cursor < buflen; cursor++ {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
continue
|
||||
case 'n':
|
||||
buflen := int64(len(buf))
|
||||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
return cursor, nil
|
||||
|
@ -116,7 +115,7 @@ func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
|
|||
cursor = c
|
||||
}
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ']':
|
||||
cursor++
|
||||
return cursor, nil
|
||||
|
@ -124,7 +123,7 @@ func (d *arrayDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
|
|||
idx++
|
||||
continue
|
||||
default:
|
||||
return 0, errInvalidCharacter(buf[cursor], "array", cursor)
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor), "array", cursor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,22 +94,22 @@ ERROR:
|
|||
return errUnexpectedEndOfJSON("bool", s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *boolDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(len(buf))
|
||||
func (d *boolDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(buf.len)
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case 't':
|
||||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("bool(true)", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'r' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "bool(true)", cursor)
|
||||
if char(buf.data, cursor+1) != 'r' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "bool(true)", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "bool(true)", cursor)
|
||||
if char(buf.data, cursor+2) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "bool(true)", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'e' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "bool(true)", cursor)
|
||||
if char(buf.data, cursor+3) != 'e' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "bool(true)", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
**(**bool)(unsafe.Pointer(&p)) = true
|
||||
|
@ -118,17 +118,17 @@ func (d *boolDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
|||
if cursor+4 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'a' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+1) != 'a' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 's' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+3) != 's' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+4] != 'e' {
|
||||
return 0, errInvalidCharacter(buf[cursor+4], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+4) != 'e' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+4), "bool(false)", cursor)
|
||||
}
|
||||
cursor += 5
|
||||
**(**bool)(unsafe.Pointer(&p)) = false
|
||||
|
@ -137,14 +137,14 @@ func (d *boolDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
|||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
**(**bool)(unsafe.Pointer(&p)) = false
|
||||
|
|
|
@ -54,7 +54,7 @@ func (d *bytesDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *bytesDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *bytesDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.decodeBinary(buf, cursor, p)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -128,18 +128,18 @@ func (d *bytesDecoder) decodeStreamBinary(s *stream, p unsafe.Pointer) ([]byte,
|
|||
return nil, errNotAtBeginningOfValue(s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *bytesDecoder) decodeBinary(buf []byte, cursor int64, p unsafe.Pointer) ([]byte, int64, error) {
|
||||
func (d *bytesDecoder) decodeBinary(buf *sliceHeader, cursor int64, p unsafe.Pointer) ([]byte, int64, error) {
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
cursor++
|
||||
case '"':
|
||||
cursor++
|
||||
start := cursor
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '"':
|
||||
literal := buf[start:cursor]
|
||||
literal := (*(*[]byte)(unsafe.Pointer(buf)))[start:cursor]
|
||||
cursor++
|
||||
return literal, cursor, nil
|
||||
case nul:
|
||||
|
@ -160,18 +160,18 @@ func (d *bytesDecoder) decodeBinary(buf []byte, cursor int64, p unsafe.Pointer)
|
|||
}
|
||||
return nil, c, nil
|
||||
case 'n':
|
||||
buflen := int64(len(buf))
|
||||
buflen := int64(buf.len)
|
||||
if cursor+3 >= buflen {
|
||||
return nil, 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return nil, 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return nil, 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return nil, 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return nil, 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return nil, 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return nil, 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
return []byte{}, cursor, nil
|
||||
|
|
|
@ -11,23 +11,23 @@ func init() {
|
|||
isWhiteSpace['\r'] = true
|
||||
}
|
||||
|
||||
func skipWhiteSpace(buf []byte, cursor int64) int64 {
|
||||
func skipWhiteSpace(buf *sliceHeader, cursor int64) int64 {
|
||||
LOOP:
|
||||
if isWhiteSpace[buf[cursor]] {
|
||||
if isWhiteSpace[char(buf.data, cursor)] {
|
||||
cursor++
|
||||
goto LOOP
|
||||
}
|
||||
return cursor
|
||||
}
|
||||
|
||||
func skipValue(buf []byte, cursor int64) (int64, error) {
|
||||
func skipValue(buf *sliceHeader, cursor int64) (int64, error) {
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
braceCount := 0
|
||||
bracketCount := 0
|
||||
buflen := int64(len(buf))
|
||||
buflen := int64(buf.len)
|
||||
start := cursor
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case nul:
|
||||
if start == cursor {
|
||||
return cursor, errUnexpectedEndOfJSON("value of object", cursor)
|
||||
|
@ -58,10 +58,10 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
|
|||
cursor++
|
||||
|
||||
for ; cursor < buflen; cursor++ {
|
||||
if buf[cursor] != '"' {
|
||||
if char(buf.data, cursor) != '"' {
|
||||
continue
|
||||
}
|
||||
if buf[cursor-1] == '\\' {
|
||||
if char(buf.data, cursor-1) == '\\' {
|
||||
continue
|
||||
}
|
||||
if bracketCount == 0 && braceCount == 0 {
|
||||
|
@ -72,7 +72,7 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
|
|||
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
cursor++
|
||||
for ; cursor < buflen; cursor++ {
|
||||
tk := int(buf[cursor])
|
||||
tk := int(char(buf.data, cursor))
|
||||
if (int('0') <= tk && tk <= int('9')) || tk == '.' || tk == 'e' || tk == 'E' {
|
||||
continue
|
||||
}
|
||||
|
@ -86,13 +86,13 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
|
|||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'r' {
|
||||
if char(buf.data, cursor+1) != 'r' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'u' {
|
||||
if char(buf.data, cursor+2) != 'u' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'e' {
|
||||
if char(buf.data, cursor+3) != 'e' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
|
@ -104,16 +104,16 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
|
|||
if cursor+4 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'a' {
|
||||
if char(buf.data, cursor+1) != 'a' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 's' {
|
||||
if char(buf.data, cursor+3) != 's' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
if buf[cursor+4] != 'e' {
|
||||
if char(buf.data, cursor+4) != 'e' {
|
||||
return 0, errUnexpectedEndOfJSON("bool of object", cursor)
|
||||
}
|
||||
cursor += 5
|
||||
|
@ -125,13 +125,13 @@ func skipValue(buf []byte, cursor int64) (int64, error) {
|
|||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
|
|
|
@ -85,22 +85,22 @@ ERROR:
|
|||
return nil, errUnexpectedEndOfJSON("float", s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *floatDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error) {
|
||||
buflen := int64(len(buf))
|
||||
func (d *floatDecoder) decodeByte(buf *sliceHeader, cursor int64) ([]byte, int64, error) {
|
||||
buflen := int64(buf.len)
|
||||
for ; cursor < buflen; cursor++ {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
continue
|
||||
case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
start := cursor
|
||||
cursor++
|
||||
for ; cursor < buflen; cursor++ {
|
||||
if floatTable[buf[cursor]] {
|
||||
if floatTable[char(buf.data, cursor)] {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
num := buf[start:cursor]
|
||||
num := (*(*[]byte)(unsafe.Pointer(buf)))[start:cursor]
|
||||
return num, cursor, nil
|
||||
default:
|
||||
return nil, 0, errUnexpectedEndOfJSON("float", cursor)
|
||||
|
@ -123,13 +123,13 @@ func (d *floatDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *floatDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *floatDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
cursor = c
|
||||
if !validEndNumberChar[buf[cursor]] {
|
||||
if !validEndNumberChar[char(buf.data, cursor)] {
|
||||
return 0, errUnexpectedEndOfJSON("float", cursor)
|
||||
}
|
||||
s := *(*string)(unsafe.Pointer(&bytes))
|
||||
|
|
|
@ -129,9 +129,9 @@ ERROR:
|
|||
return nil, errUnexpectedEndOfJSON("number(integer)", s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *intDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error) {
|
||||
func (d *intDecoder) decodeByte(buf *sliceHeader, cursor int64) ([]byte, int64, error) {
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
cursor++
|
||||
continue
|
||||
|
@ -139,14 +139,14 @@ func (d *intDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error)
|
|||
start := cursor
|
||||
cursor++
|
||||
LOOP:
|
||||
if numTable[buf[cursor]] {
|
||||
if numTable[char(buf.data, cursor)] {
|
||||
cursor++
|
||||
goto LOOP
|
||||
}
|
||||
num := buf[start:cursor]
|
||||
num := (*(*[]byte)(unsafe.Pointer(buf)))[start:cursor]
|
||||
return num, cursor, nil
|
||||
default:
|
||||
return nil, 0, d.typeError([]byte{buf[cursor]}, cursor)
|
||||
return nil, 0, d.typeError([]byte{char(buf.data, cursor)}, cursor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ func (d *intDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *intDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *intDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -171,9 +171,9 @@ func (d *interfaceDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return errNotAtBeginningOfValue(s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *interfaceDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '{':
|
||||
var v map[string]interface{}
|
||||
ptr := unsafe.Pointer(&v)
|
||||
|
@ -214,12 +214,12 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i
|
|||
cursor++
|
||||
start := cursor
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '\\':
|
||||
cursor++
|
||||
continue
|
||||
case '"':
|
||||
literal := buf[start:cursor]
|
||||
literal := (*(*[]byte)(unsafe.Pointer(buf)))[start:cursor]
|
||||
cursor++
|
||||
**(**interface{})(unsafe.Pointer(&p)) = *(*string)(unsafe.Pointer(&literal))
|
||||
return cursor, nil
|
||||
|
@ -229,52 +229,52 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i
|
|||
cursor++
|
||||
}
|
||||
case 't':
|
||||
if cursor+3 >= int64(len(buf)) {
|
||||
if cursor+3 >= int64(buf.len) {
|
||||
return 0, errUnexpectedEndOfJSON("bool(true)", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'r' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "bool(true)", cursor)
|
||||
if char(buf.data, cursor+1) != 'r' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "bool(true)", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "bool(true)", cursor)
|
||||
if char(buf.data, cursor+2) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "bool(true)", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'e' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "bool(true)", cursor)
|
||||
if char(buf.data, cursor+3) != 'e' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "bool(true)", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
**(**interface{})(unsafe.Pointer(&p)) = true
|
||||
return cursor, nil
|
||||
case 'f':
|
||||
if cursor+4 >= int64(len(buf)) {
|
||||
if cursor+4 >= int64(buf.len) {
|
||||
return 0, errUnexpectedEndOfJSON("bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'a' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+1) != 'a' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 's' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+3) != 's' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "bool(false)", cursor)
|
||||
}
|
||||
if buf[cursor+4] != 'e' {
|
||||
return 0, errInvalidCharacter(buf[cursor+4], "bool(false)", cursor)
|
||||
if char(buf.data, cursor+4) != 'e' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+4), "bool(false)", cursor)
|
||||
}
|
||||
cursor += 5
|
||||
**(**interface{})(unsafe.Pointer(&p)) = false
|
||||
return cursor, nil
|
||||
case 'n':
|
||||
if cursor+3 >= int64(len(buf)) {
|
||||
if cursor+3 >= int64(buf.len) {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
**(**interface{})(unsafe.Pointer(&p)) = nil
|
||||
|
|
|
@ -33,12 +33,12 @@ func makemap(*rtype, int) unsafe.Pointer
|
|||
//go:noescape
|
||||
func mapassign(t *rtype, m unsafe.Pointer, key, val unsafe.Pointer)
|
||||
|
||||
func (d *mapDecoder) setKey(buf []byte, cursor int64, key interface{}) (int64, error) {
|
||||
func (d *mapDecoder) setKey(buf *sliceHeader, cursor int64, key interface{}) (int64, error) {
|
||||
header := (*interfaceHeader)(unsafe.Pointer(&key))
|
||||
return d.keyDecoder.decode(buf, cursor, header.ptr)
|
||||
}
|
||||
|
||||
func (d *mapDecoder) setValue(buf []byte, cursor int64, key interface{}) (int64, error) {
|
||||
func (d *mapDecoder) setValue(buf *sliceHeader, cursor int64, key interface{}) (int64, error) {
|
||||
header := (*interfaceHeader)(unsafe.Pointer(&key))
|
||||
return d.valueDecoder.decode(buf, cursor, header.ptr)
|
||||
}
|
||||
|
@ -96,25 +96,25 @@ func (d *mapDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *mapDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *mapDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
buflen := int64(len(buf))
|
||||
buflen := int64(buf.len)
|
||||
if buflen < 2 {
|
||||
return 0, errExpected("{} for map", cursor)
|
||||
}
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case 'n':
|
||||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
return cursor, nil
|
||||
|
@ -125,7 +125,7 @@ func (d *mapDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
|||
cursor++
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
mapValue := makemap(d.mapType, 0)
|
||||
if buf[cursor] == '}' {
|
||||
if char(buf.data, cursor) == '}' {
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||
cursor++
|
||||
return cursor, nil
|
||||
|
@ -138,7 +138,7 @@ func (d *mapDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
|||
}
|
||||
cursor = keyCursor
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
if buf[cursor] != ':' {
|
||||
if char(buf.data, cursor) != ':' {
|
||||
return 0, errExpected("colon after object key", cursor)
|
||||
}
|
||||
cursor++
|
||||
|
@ -152,12 +152,12 @@ func (d *mapDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
|||
}
|
||||
mapassign(d.mapType, mapValue, unsafe.Pointer(&key), unsafe.Pointer(&value))
|
||||
cursor = skipWhiteSpace(buf, valueCursor)
|
||||
if buf[cursor] == '}' {
|
||||
if char(buf.data, cursor) == '}' {
|
||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||
cursor++
|
||||
return cursor, nil
|
||||
}
|
||||
if buf[cursor] != ',' {
|
||||
if char(buf.data, cursor) != ',' {
|
||||
return 0, errExpected("comma after object value", cursor)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func (d *numberDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *numberDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *numberDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.floatDecoder.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -52,21 +52,21 @@ func (d *ptrDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *ptrDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *ptrDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
if buf[cursor] == 'n' {
|
||||
buflen := int64(len(buf))
|
||||
if char(buf.data, cursor) == 'n' {
|
||||
buflen := int64(buf.len)
|
||||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
*(*unsafe.Pointer)(p) = nil
|
||||
cursor += 4
|
||||
|
|
|
@ -148,32 +148,32 @@ ERROR:
|
|||
return errUnexpectedEndOfJSON("slice", s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *sliceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(len(buf))
|
||||
func (d *sliceDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(buf.len)
|
||||
for ; cursor < buflen; cursor++ {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
continue
|
||||
case 'n':
|
||||
buflen := int64(len(buf))
|
||||
buflen := int64(buf.len)
|
||||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
return cursor, nil
|
||||
case '[':
|
||||
cursor++
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
if buf[cursor] == ']' {
|
||||
if char(buf.data, cursor) == ']' {
|
||||
**(**sliceHeader)(unsafe.Pointer(&p)) = sliceHeader{
|
||||
data: newArray(d.elemType, 0),
|
||||
len: 0,
|
||||
|
@ -200,7 +200,7 @@ func (d *sliceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
|
|||
}
|
||||
cursor = c
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ']':
|
||||
slice.cap = cap
|
||||
slice.len = idx + 1
|
||||
|
@ -226,7 +226,7 @@ func (d *sliceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64
|
|||
slice.cap = cap
|
||||
slice.data = data
|
||||
d.releaseSlice(slice)
|
||||
return 0, errInvalidCharacter(buf[cursor], "slice", cursor)
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor), "slice", cursor)
|
||||
}
|
||||
cursor++
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func (d *stringDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *stringDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *stringDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -237,9 +237,9 @@ func (d *stringDecoder) decodeStreamByte(s *stream) ([]byte, error) {
|
|||
return nil, errNotAtBeginningOfValue(s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *stringDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error) {
|
||||
func (d *stringDecoder) decodeByte(buf *sliceHeader, cursor int64) ([]byte, int64, error) {
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
cursor++
|
||||
case '[':
|
||||
|
@ -250,48 +250,50 @@ func (d *stringDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, err
|
|||
cursor++
|
||||
start := cursor
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '\\':
|
||||
cursor++
|
||||
switch buf[cursor] {
|
||||
b := (*(*[]byte)(unsafe.Pointer(buf)))
|
||||
switch char(buf.data, cursor) {
|
||||
case '"':
|
||||
buf[cursor] = '"'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '"'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case '\\':
|
||||
buf[cursor] = '\\'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '\\'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case '/':
|
||||
buf[cursor] = '/'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '/'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case 'b':
|
||||
buf[cursor] = '\b'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '\b'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case 'f':
|
||||
buf[cursor] = '\f'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '\f'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case 'n':
|
||||
buf[cursor] = '\n'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '\n'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case 'r':
|
||||
buf[cursor] = '\r'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '\r'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case 't':
|
||||
buf[cursor] = '\t'
|
||||
buf = append(buf[:cursor-1], buf[cursor:]...)
|
||||
b[cursor] = '\t'
|
||||
b = append(b[:cursor-1], b[cursor:]...)
|
||||
case 'u':
|
||||
buflen := int64(len(buf))
|
||||
buflen := int64(buf.len)
|
||||
if cursor+5 >= buflen {
|
||||
return nil, 0, errUnexpectedEndOfJSON("escaped string", cursor)
|
||||
}
|
||||
code := unicodeToRune(buf[cursor+1 : cursor+5])
|
||||
code := unicodeToRune(b[cursor+1 : cursor+5])
|
||||
unicode := []byte(string(code))
|
||||
buf = append(append(buf[:cursor-1], unicode...), buf[cursor+5:]...)
|
||||
b = append(append(b[:cursor-1], unicode...), b[cursor+5:]...)
|
||||
default:
|
||||
return nil, 0, errUnexpectedEndOfJSON("escaped string", cursor)
|
||||
}
|
||||
buf = (*sliceHeader)(unsafe.Pointer(&b))
|
||||
continue
|
||||
case '"':
|
||||
literal := buf[start:cursor]
|
||||
literal := (*(*[]byte)(unsafe.Pointer(buf)))[start:cursor]
|
||||
cursor++
|
||||
return literal, cursor, nil
|
||||
case nul:
|
||||
|
@ -300,18 +302,18 @@ func (d *stringDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, err
|
|||
cursor++
|
||||
}
|
||||
case 'n':
|
||||
buflen := int64(len(buf))
|
||||
buflen := int64(buf.len)
|
||||
if cursor+3 >= buflen {
|
||||
return nil, 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return nil, 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return nil, 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return nil, 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return nil, 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return nil, 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return nil, 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
return []byte{}, cursor, nil
|
||||
|
|
|
@ -23,7 +23,7 @@ type structDecoder struct {
|
|||
keyBitmapInt8 [][256]int8
|
||||
keyBitmapInt16 [][256]int16
|
||||
sortedFieldSets []*structFieldSet
|
||||
keyDecoder func(*structDecoder, []byte, int64) (int64, *structFieldSet, error)
|
||||
keyDecoder func(*structDecoder, *sliceHeader, int64) (int64, *structFieldSet, error)
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -115,18 +115,18 @@ func (d *structDecoder) tryOptimize() {
|
|||
}
|
||||
}
|
||||
|
||||
func decodeKeyByBitmapInt8(d *structDecoder, buf []byte, cursor int64) (int64, *structFieldSet, error) {
|
||||
func decodeKeyByBitmapInt8(d *structDecoder, buf *sliceHeader, cursor int64) (int64, *structFieldSet, error) {
|
||||
var (
|
||||
field *structFieldSet
|
||||
curBit int8 = math.MaxInt8
|
||||
)
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
cursor++
|
||||
case '"':
|
||||
cursor++
|
||||
c := buf[cursor]
|
||||
c := char(buf.data, cursor)
|
||||
switch c {
|
||||
case '"':
|
||||
cursor++
|
||||
|
@ -138,7 +138,7 @@ func decodeKeyByBitmapInt8(d *structDecoder, buf []byte, cursor int64) (int64, *
|
|||
bitmap := d.keyBitmapInt8
|
||||
keyBitmapLen := len(bitmap)
|
||||
for {
|
||||
c := buf[cursor]
|
||||
c := char(buf.data, cursor)
|
||||
switch c {
|
||||
case '"':
|
||||
x := uint64(curBit & -curBit)
|
||||
|
@ -152,13 +152,13 @@ func decodeKeyByBitmapInt8(d *structDecoder, buf []byte, cursor int64) (int64, *
|
|||
if keyIdx >= keyBitmapLen {
|
||||
for {
|
||||
cursor++
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '"':
|
||||
cursor++
|
||||
return cursor, field, nil
|
||||
case '\\':
|
||||
cursor++
|
||||
if buf[cursor] == nul {
|
||||
if char(buf.data, cursor) == nul {
|
||||
return 0, nil, errUnexpectedEndOfJSON("string", cursor)
|
||||
}
|
||||
case nul:
|
||||
|
@ -170,13 +170,13 @@ func decodeKeyByBitmapInt8(d *structDecoder, buf []byte, cursor int64) (int64, *
|
|||
if curBit == 0 {
|
||||
for {
|
||||
cursor++
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '"':
|
||||
cursor++
|
||||
return cursor, field, nil
|
||||
case '\\':
|
||||
cursor++
|
||||
if buf[cursor] == nul {
|
||||
if char(buf.data, cursor) == nul {
|
||||
return 0, nil, errUnexpectedEndOfJSON("string", cursor)
|
||||
}
|
||||
case nul:
|
||||
|
@ -194,18 +194,22 @@ func decodeKeyByBitmapInt8(d *structDecoder, buf []byte, cursor int64) (int64, *
|
|||
}
|
||||
}
|
||||
|
||||
func decodeKeyByBitmapInt16(d *structDecoder, buf []byte, cursor int64) (int64, *structFieldSet, error) {
|
||||
func char(ptr unsafe.Pointer, offset int64) byte {
|
||||
return *(*byte)(unsafe.Pointer(uintptr(ptr) + uintptr(offset)))
|
||||
}
|
||||
|
||||
func decodeKeyByBitmapInt16(d *structDecoder, buf *sliceHeader, cursor int64) (int64, *structFieldSet, error) {
|
||||
var (
|
||||
field *structFieldSet
|
||||
curBit int16 = math.MaxInt16
|
||||
)
|
||||
for {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
cursor++
|
||||
case '"':
|
||||
cursor++
|
||||
c := buf[cursor]
|
||||
c := char(buf.data, cursor)
|
||||
switch c {
|
||||
case '"':
|
||||
cursor++
|
||||
|
@ -217,7 +221,7 @@ func decodeKeyByBitmapInt16(d *structDecoder, buf []byte, cursor int64) (int64,
|
|||
bitmap := d.keyBitmapInt16
|
||||
keyBitmapLen := len(bitmap)
|
||||
for {
|
||||
c := buf[cursor]
|
||||
c := char(buf.data, cursor)
|
||||
switch c {
|
||||
case '"':
|
||||
x := uint64(curBit & -curBit)
|
||||
|
@ -231,13 +235,13 @@ func decodeKeyByBitmapInt16(d *structDecoder, buf []byte, cursor int64) (int64,
|
|||
if keyIdx >= keyBitmapLen {
|
||||
for {
|
||||
cursor++
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '"':
|
||||
cursor++
|
||||
return cursor, field, nil
|
||||
case '\\':
|
||||
cursor++
|
||||
if buf[cursor] == nul {
|
||||
if char(buf.data, cursor) == nul {
|
||||
return 0, nil, errUnexpectedEndOfJSON("string", cursor)
|
||||
}
|
||||
case nul:
|
||||
|
@ -249,13 +253,13 @@ func decodeKeyByBitmapInt16(d *structDecoder, buf []byte, cursor int64) (int64,
|
|||
if curBit == 0 {
|
||||
for {
|
||||
cursor++
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case '"':
|
||||
cursor++
|
||||
return cursor, field, nil
|
||||
case '\\':
|
||||
cursor++
|
||||
if buf[cursor] == nul {
|
||||
if char(buf.data, cursor) == nul {
|
||||
return 0, nil, errUnexpectedEndOfJSON("string", cursor)
|
||||
}
|
||||
case nul:
|
||||
|
@ -273,7 +277,7 @@ func decodeKeyByBitmapInt16(d *structDecoder, buf []byte, cursor int64) (int64,
|
|||
}
|
||||
}
|
||||
|
||||
func decodeKey(d *structDecoder, buf []byte, cursor int64) (int64, *structFieldSet, error) {
|
||||
func decodeKey(d *structDecoder, buf *sliceHeader, cursor int64) (int64, *structFieldSet, error) {
|
||||
key, c, err := d.stringDecoder.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
|
@ -355,23 +359,22 @@ 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))
|
||||
func (d *structDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
buflen := int64(buf.len)
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case 'n':
|
||||
buflen := int64(len(buf))
|
||||
if cursor+3 >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("null", cursor)
|
||||
}
|
||||
if buf[cursor+1] != 'u' {
|
||||
return 0, errInvalidCharacter(buf[cursor+1], "null", cursor)
|
||||
if char(buf.data, cursor+1) != 'u' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+1), "null", cursor)
|
||||
}
|
||||
if buf[cursor+2] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+2], "null", cursor)
|
||||
if char(buf.data, cursor+2) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+2), "null", cursor)
|
||||
}
|
||||
if buf[cursor+3] != 'l' {
|
||||
return 0, errInvalidCharacter(buf[cursor+3], "null", cursor)
|
||||
if char(buf.data, cursor+3) != 'l' {
|
||||
return 0, errInvalidCharacter(char(buf.data, cursor+3), "null", cursor)
|
||||
}
|
||||
cursor += 4
|
||||
return cursor, nil
|
||||
|
@ -390,11 +393,11 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
|
|||
}
|
||||
cursor = c
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
if buf[cursor] != ':' {
|
||||
if char(buf.data, 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 {
|
||||
|
@ -411,11 +414,11 @@ func (d *structDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int6
|
|||
cursor = c
|
||||
}
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
if buf[cursor] == '}' {
|
||||
if char(buf.data, cursor) == '}' {
|
||||
cursor++
|
||||
return cursor, nil
|
||||
}
|
||||
if buf[cursor] != ',' {
|
||||
if char(buf.data, cursor) != ',' {
|
||||
return 0, errExpected("comma after object element", cursor)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,26 +82,26 @@ func (d *uintDecoder) decodeStreamByte(s *stream) ([]byte, error) {
|
|||
return nil, errUnexpectedEndOfJSON("number(unsigned integer)", s.totalOffset())
|
||||
}
|
||||
|
||||
func (d *uintDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error) {
|
||||
buflen := int64(len(buf))
|
||||
func (d *uintDecoder) decodeByte(buf *sliceHeader, cursor int64) ([]byte, int64, error) {
|
||||
buflen := int64(buf.len)
|
||||
for ; cursor < buflen; cursor++ {
|
||||
switch buf[cursor] {
|
||||
switch char(buf.data, cursor) {
|
||||
case ' ', '\n', '\t', '\r':
|
||||
continue
|
||||
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
start := cursor
|
||||
cursor++
|
||||
for ; cursor < buflen; cursor++ {
|
||||
tk := int(buf[cursor])
|
||||
tk := int(char(buf.data, cursor))
|
||||
if int('0') <= tk && tk <= int('9') {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
num := buf[start:cursor]
|
||||
num := (*(*[]byte)(unsafe.Pointer(buf)))[start:cursor]
|
||||
return num, cursor, nil
|
||||
default:
|
||||
return nil, 0, d.typeError([]byte{buf[cursor]}, cursor)
|
||||
return nil, 0, d.typeError([]byte{char(buf.data, cursor)}, cursor)
|
||||
}
|
||||
}
|
||||
return nil, 0, errUnexpectedEndOfJSON("number(unsigned integer)", cursor)
|
||||
|
@ -131,7 +131,7 @@ func (d *uintDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *uintDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *uintDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
|
@ -49,14 +49,14 @@ func (d *unmarshalJSONDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *unmarshalJSONDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *unmarshalJSONDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
start := cursor
|
||||
end, err := skipValue(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
src := buf[start:end]
|
||||
src := (*(*[]byte)(unsafe.Pointer(buf)))[start:end]
|
||||
dst := make([]byte, len(src))
|
||||
copy(dst, src)
|
||||
|
||||
|
|
|
@ -72,14 +72,14 @@ func (d *unmarshalTextDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *unmarshalTextDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *unmarshalTextDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
start := cursor
|
||||
end, err := skipValue(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
src := buf[start:end]
|
||||
src := (*(*[]byte)(unsafe.Pointer(buf)))[start:end]
|
||||
if s, ok := unquoteBytes(src); ok {
|
||||
src = s
|
||||
}
|
||||
|
|
|
@ -27,19 +27,19 @@ func (d *wrappedStringDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
|
|||
}
|
||||
b := make([]byte, len(bytes)+1)
|
||||
copy(b, bytes)
|
||||
if _, err := d.dec.decode(b, 0, p); err != nil {
|
||||
if _, err := d.dec.decode((*sliceHeader)(unsafe.Pointer(&b)), 0, p); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *wrappedStringDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
func (d *wrappedStringDecoder) decode(buf *sliceHeader, cursor int64, p unsafe.Pointer) (int64, error) {
|
||||
bytes, c, err := d.stringDecoder.decodeByte(buf, cursor)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
bytes = append(bytes, nul)
|
||||
if _, err := d.dec.decode(bytes, 0, p); err != nil {
|
||||
if _, err := d.dec.decode((*sliceHeader)(unsafe.Pointer(&bytes)), 0, p); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return c, nil
|
||||
|
|
Loading…
Reference in New Issue