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