1
0
mirror of https://github.com/json-iterator/go.git synced 2025-06-24 23:16:47 +02:00

optimize read nil/true/false

This commit is contained in:
Tao Wen
2017-01-18 23:33:40 +08:00
parent 6efc6c44ac
commit a73e48e8bf
8 changed files with 216 additions and 202 deletions

@ -140,7 +140,7 @@ type optionalEncoder struct {
func (encoder *optionalEncoder) encode(ptr unsafe.Pointer, stream *Stream) {
if *((*unsafe.Pointer)(ptr)) == nil {
stream.WriteNull()
stream.WriteNil()
} else {
encoder.valueEncoder.encode(*((*unsafe.Pointer)(ptr)), stream)
}
@ -322,6 +322,10 @@ func (iter *Iterator) ReadVal(obj interface{}) {
func (stream *Stream) WriteVal(val interface{}) {
if nil == val {
stream.WriteNil()
return
}
typ := reflect.TypeOf(val)
cacheKey := typ
cachedEncoder := getEncoderFromCache(cacheKey)