1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-20 11:28:49 +02:00

get decoder without get type first

This commit is contained in:
Tao Wen 2018-02-22 10:18:27 +08:00
parent df8295a48a
commit 820ec30bd6

View File

@ -51,12 +51,16 @@ func (b *ctx) append(prefix string) *ctx {
// ReadVal copy the underlying JSON into go interface, same as json.Unmarshal // ReadVal copy the underlying JSON into go interface, same as json.Unmarshal
func (iter *Iterator) ReadVal(obj interface{}) { func (iter *Iterator) ReadVal(obj interface{}) {
typ := reflect2.TypeOf(obj) cacheKey := reflect2.RTypeOf(obj)
if typ.Kind() != reflect.Ptr { decoder := iter.cfg.getDecoderFromCache(cacheKey)
iter.ReportError("ReadVal", "can only unmarshal into pointer") if decoder == nil {
return typ := reflect2.TypeOf(obj)
if typ.Kind() != reflect.Ptr {
iter.ReportError("ReadVal", "can only unmarshal into pointer")
return
}
decoder = iter.cfg.DecoderOf(typ)
} }
decoder := iter.cfg.DecoderOf(typ)
ptr := reflect2.PtrOf(obj) ptr := reflect2.PtrOf(obj)
if ptr == nil { if ptr == nil {
iter.ReportError("ReadVal", "can not read into nil pointer") iter.ReportError("ReadVal", "can not read into nil pointer")