mirror of https://github.com/goccy/go-json.git
Use pre-allocated buffer for zero character
This commit is contained in:
parent
fee2d1fc68
commit
80719cf181
|
@ -79,6 +79,10 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
var (
|
||||
numZeroBuf = []byte{'0'}
|
||||
)
|
||||
|
||||
func (d *intDecoder) decodeStreamByte(s *stream) ([]byte, error) {
|
||||
for {
|
||||
switch s.char() {
|
||||
|
@ -106,7 +110,7 @@ func (d *intDecoder) decodeStreamByte(s *stream) ([]byte, error) {
|
|||
return num, nil
|
||||
case '0':
|
||||
s.cursor++
|
||||
return []byte{'0'}, nil
|
||||
return numZeroBuf, nil
|
||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
start := s.cursor
|
||||
for {
|
||||
|
@ -150,7 +154,7 @@ func (d *intDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error)
|
|||
continue
|
||||
case '0':
|
||||
cursor++
|
||||
return []byte{'0'}, cursor, nil
|
||||
return numZeroBuf, cursor, nil
|
||||
case '-', '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
start := cursor
|
||||
cursor++
|
||||
|
|
|
@ -62,7 +62,7 @@ func (d *uintDecoder) decodeStreamByte(s *stream) ([]byte, error) {
|
|||
continue
|
||||
case '0':
|
||||
s.cursor++
|
||||
return []byte{'0'}, nil
|
||||
return numZeroBuf, nil
|
||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
start := s.cursor
|
||||
for {
|
||||
|
@ -104,7 +104,7 @@ func (d *uintDecoder) decodeByte(buf []byte, cursor int64) ([]byte, int64, error
|
|||
continue
|
||||
case '0':
|
||||
cursor++
|
||||
return []byte{'0'}, cursor, nil
|
||||
return numZeroBuf, cursor, nil
|
||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9':
|
||||
start := cursor
|
||||
cursor++
|
||||
|
|
Loading…
Reference in New Issue