Explorar o código

get encoder without get type first

Tao Wen %!s(int64=7) %!d(string=hai) anos
pai
achega
d346ea6e55
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      reflect.go

+ 6 - 2
reflect.go

@@ -75,8 +75,12 @@ func (stream *Stream) WriteVal(val interface{}) {
 		stream.WriteNil()
 		return
 	}
-	typ := reflect2.TypeOf(val)
-	encoder := stream.cfg.EncoderOf(typ)
+	cacheKey := reflect2.RTypeOf(val)
+	encoder := stream.cfg.getEncoderFromCache(cacheKey)
+	if encoder == nil {
+		typ := reflect2.TypeOf(val)
+		encoder = stream.cfg.EncoderOf(typ)
+	}
 	encoder.Encode(reflect2.PtrOf(val), stream)
 }