1
0
mirror of https://github.com/json-iterator/go.git synced 2024-11-27 08:30:57 +02:00

tweak performance

This commit is contained in:
Tao Wen 2017-06-17 22:42:11 +08:00
parent 8ab46965bd
commit 77dcffe77d
2 changed files with 8 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package jsoniter
import ( import (
"fmt" "fmt"
"unicode" "unicode"
"unsafe"
) )
func (iter *Iterator) ReadObject() (ret string) { func (iter *Iterator) ReadObject() (ret string) {
@ -79,13 +80,13 @@ func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool {
c = iter.nextToken() c = iter.nextToken()
if c == '"' { if c == '"' {
iter.unreadByte() iter.unreadByte()
field := string(iter.readObjectFieldAsBytes()) field := iter.readObjectFieldAsBytes()
if !callback(iter, field) { if !callback(iter, *(*string)(unsafe.Pointer(&field))) {
return false return false
} }
for iter.nextToken() == ',' { for iter.nextToken() == ',' {
field = string(iter.readObjectFieldAsBytes()) field = iter.readObjectFieldAsBytes()
if !callback(iter, field) { if !callback(iter, *(*string)(unsafe.Pointer(&field))) {
return false return false
} }
} }

View File

@ -1,6 +1,8 @@
package jsoniter package jsoniter
import "io" import (
"io"
)
func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream { func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream {
select { select {