mirror of https://github.com/goccy/go-json.git
Fix decoderMap interface
This commit is contained in:
parent
bad57364aa
commit
82e8cc766f
20
decode.go
20
decode.go
|
@ -35,14 +35,14 @@ type decoderMap struct {
|
||||||
sync.Map
|
sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *decoderMap) Get(k string) decoder {
|
func (m *decoderMap) get(k uintptr) decoder {
|
||||||
if v, ok := m.Load(k); ok {
|
if v, ok := m.Load(k); ok {
|
||||||
return v.(decoder)
|
return v.(decoder)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *decoderMap) Set(k string, dec decoder) {
|
func (m *decoderMap) set(k uintptr, dec decoder) {
|
||||||
m.Store(k, dec)
|
m.Store(k, dec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,16 +79,14 @@ func (d *Decoder) decode(src []byte, header *interfaceHeader) error {
|
||||||
if typ.Kind() != reflect.Ptr {
|
if typ.Kind() != reflect.Ptr {
|
||||||
return ErrDecodePointer
|
return ErrDecodePointer
|
||||||
}
|
}
|
||||||
name := typ.String()
|
typeptr := uintptr(unsafe.Pointer(typ))
|
||||||
dec := cachedDecoder.Get(name)
|
dec := cachedDecoder.get(typeptr)
|
||||||
if dec == nil {
|
if dec == nil {
|
||||||
compiledDec, err := d.compile(typ.Elem())
|
compiledDec, err := d.compile(typ.Elem())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if name != "" {
|
cachedDecoder.set(typeptr, compiledDec)
|
||||||
cachedDecoder.Set(name, compiledDec)
|
|
||||||
}
|
|
||||||
dec = compiledDec
|
dec = compiledDec
|
||||||
}
|
}
|
||||||
ptr := uintptr(header.ptr)
|
ptr := uintptr(header.ptr)
|
||||||
|
@ -124,16 +122,14 @@ func (d *Decoder) Decode(v interface{}) error {
|
||||||
if typ.Kind() != reflect.Ptr {
|
if typ.Kind() != reflect.Ptr {
|
||||||
return ErrDecodePointer
|
return ErrDecodePointer
|
||||||
}
|
}
|
||||||
name := typ.String()
|
typeptr := uintptr(unsafe.Pointer(typ))
|
||||||
dec := cachedDecoder.Get(name)
|
dec := cachedDecoder.get(typeptr)
|
||||||
if dec == nil {
|
if dec == nil {
|
||||||
compiledDec, err := d.compile(typ.Elem())
|
compiledDec, err := d.compile(typ.Elem())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if name != "" {
|
cachedDecoder.set(typeptr, compiledDec)
|
||||||
cachedDecoder.Set(name, compiledDec)
|
|
||||||
}
|
|
||||||
dec = compiledDec
|
dec = compiledDec
|
||||||
}
|
}
|
||||||
ptr := uintptr(header.ptr)
|
ptr := uintptr(header.ptr)
|
||||||
|
|
Loading…
Reference in New Issue