From 82e8cc766f9f0efe175aef7b30b53924c35813b9 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 6 May 2020 22:22:13 +0900 Subject: [PATCH] Fix decoderMap interface --- decode.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/decode.go b/decode.go index be867cc..a24864f 100644 --- a/decode.go +++ b/decode.go @@ -35,14 +35,14 @@ type decoderMap struct { sync.Map } -func (m *decoderMap) Get(k string) decoder { +func (m *decoderMap) get(k uintptr) decoder { if v, ok := m.Load(k); ok { return v.(decoder) } return nil } -func (m *decoderMap) Set(k string, dec decoder) { +func (m *decoderMap) set(k uintptr, dec decoder) { m.Store(k, dec) } @@ -79,16 +79,14 @@ func (d *Decoder) decode(src []byte, header *interfaceHeader) error { if typ.Kind() != reflect.Ptr { return ErrDecodePointer } - name := typ.String() - dec := cachedDecoder.Get(name) + typeptr := uintptr(unsafe.Pointer(typ)) + dec := cachedDecoder.get(typeptr) if dec == nil { compiledDec, err := d.compile(typ.Elem()) if err != nil { return err } - if name != "" { - cachedDecoder.Set(name, compiledDec) - } + cachedDecoder.set(typeptr, compiledDec) dec = compiledDec } ptr := uintptr(header.ptr) @@ -124,16 +122,14 @@ func (d *Decoder) Decode(v interface{}) error { if typ.Kind() != reflect.Ptr { return ErrDecodePointer } - name := typ.String() - dec := cachedDecoder.Get(name) + typeptr := uintptr(unsafe.Pointer(typ)) + dec := cachedDecoder.get(typeptr) if dec == nil { compiledDec, err := d.compile(typ.Elem()) if err != nil { return err } - if name != "" { - cachedDecoder.Set(name, compiledDec) - } + cachedDecoder.set(typeptr, compiledDec) dec = compiledDec } ptr := uintptr(header.ptr)