Remove unnecessary dependency on decoder

This commit is contained in:
Masaaki Goshima 2021-02-11 00:33:54 +09:00
parent d7c9594839
commit 3b7d5a6996
5 changed files with 77 additions and 82 deletions

View File

@ -68,7 +68,7 @@ func (d *Decoder) decode(src []byte, header *interfaceHeader) error {
if err := d.validateType(copiedType, ptr); err != nil { if err := d.validateType(copiedType, ptr); err != nil {
return err return err
} }
dec, err := d.compileToGetDecoder(typeptr, typ) dec, err := decodeCompileToGetDecoder(typeptr, typ)
if err != nil { if err != nil {
return err return err
} }
@ -127,7 +127,7 @@ func (d *Decoder) Decode(v interface{}) error {
return err return err
} }
dec, err := d.compileToGetDecoder(typeptr, typ) dec, err := decodeCompileToGetDecoder(typeptr, typ)
if err != nil { if err != nil {
return err return err
} }

View File

@ -6,14 +6,13 @@ import (
"unsafe" "unsafe"
) )
func (d *Decoder) compileToGetDecoderSlowPath(typeptr uintptr, typ *rtype) (decoder, error) { func decodeCompileToGetDecoderSlowPath(typeptr uintptr, typ *rtype) (decoder, error) {
decoderMap := loadDecoderMap() decoderMap := loadDecoderMap()
if dec, exists := decoderMap[typeptr]; exists { if dec, exists := decoderMap[typeptr]; exists {
return dec, nil return dec, nil
} }
d.structTypeToDecoder = map[uintptr]decoder{} dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
dec, err := d.compileHead(typ)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -21,17 +20,17 @@ func (d *Decoder) compileToGetDecoderSlowPath(typeptr uintptr, typ *rtype) (deco
return dec, nil return dec, nil
} }
func (d *Decoder) compileHead(typ *rtype) (decoder, error) { func decodeCompileHead(typ *rtype, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
switch { switch {
case rtype_ptrTo(typ).Implements(unmarshalJSONType): case rtype_ptrTo(typ).Implements(unmarshalJSONType):
return newUnmarshalJSONDecoder(rtype_ptrTo(typ), "", ""), nil return newUnmarshalJSONDecoder(rtype_ptrTo(typ), "", ""), nil
case rtype_ptrTo(typ).Implements(unmarshalTextType): case rtype_ptrTo(typ).Implements(unmarshalTextType):
return newUnmarshalTextDecoder(rtype_ptrTo(typ), "", ""), nil return newUnmarshalTextDecoder(rtype_ptrTo(typ), "", ""), nil
} }
return d.compile(typ.Elem(), "", "") return decodeCompile(typ.Elem(), "", "", structTypeToDecoder)
} }
func (d *Decoder) compile(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompile(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
switch { switch {
case rtype_ptrTo(typ).Implements(unmarshalJSONType): case rtype_ptrTo(typ).Implements(unmarshalJSONType):
return newUnmarshalJSONDecoder(rtype_ptrTo(typ), structName, fieldName), nil return newUnmarshalJSONDecoder(rtype_ptrTo(typ), structName, fieldName), nil
@ -41,51 +40,51 @@ func (d *Decoder) compile(typ *rtype, structName, fieldName string) (decoder, er
switch typ.Kind() { switch typ.Kind() {
case reflect.Ptr: case reflect.Ptr:
return d.compilePtr(typ, structName, fieldName) return decodeCompilePtr(typ, structName, fieldName, structTypeToDecoder)
case reflect.Struct: case reflect.Struct:
return d.compileStruct(typ, structName, fieldName) return decodeCompileStruct(typ, structName, fieldName, structTypeToDecoder)
case reflect.Slice: case reflect.Slice:
elem := typ.Elem() elem := typ.Elem()
if elem.Kind() == reflect.Uint8 { if elem.Kind() == reflect.Uint8 {
return d.compileBytes(elem, structName, fieldName) return decodeCompileBytes(elem, structName, fieldName)
} }
return d.compileSlice(typ, structName, fieldName) return decodeCompileSlice(typ, structName, fieldName, structTypeToDecoder)
case reflect.Array: case reflect.Array:
return d.compileArray(typ, structName, fieldName) return decodeCompileArray(typ, structName, fieldName, structTypeToDecoder)
case reflect.Map: case reflect.Map:
return d.compileMap(typ, structName, fieldName) return decodeCompileMap(typ, structName, fieldName, structTypeToDecoder)
case reflect.Interface: case reflect.Interface:
return d.compileInterface(typ, structName, fieldName) return decodeCompileInterface(typ, structName, fieldName)
case reflect.Uintptr: case reflect.Uintptr:
return d.compileUint(typ, structName, fieldName) return decodeCompileUint(typ, structName, fieldName)
case reflect.Int: case reflect.Int:
return d.compileInt(typ, structName, fieldName) return decodeCompileInt(typ, structName, fieldName)
case reflect.Int8: case reflect.Int8:
return d.compileInt8(typ, structName, fieldName) return decodeCompileInt8(typ, structName, fieldName)
case reflect.Int16: case reflect.Int16:
return d.compileInt16(typ, structName, fieldName) return decodeCompileInt16(typ, structName, fieldName)
case reflect.Int32: case reflect.Int32:
return d.compileInt32(typ, structName, fieldName) return decodeCompileInt32(typ, structName, fieldName)
case reflect.Int64: case reflect.Int64:
return d.compileInt64(typ, structName, fieldName) return decodeCompileInt64(typ, structName, fieldName)
case reflect.Uint: case reflect.Uint:
return d.compileUint(typ, structName, fieldName) return decodeCompileUint(typ, structName, fieldName)
case reflect.Uint8: case reflect.Uint8:
return d.compileUint8(typ, structName, fieldName) return decodeCompileUint8(typ, structName, fieldName)
case reflect.Uint16: case reflect.Uint16:
return d.compileUint16(typ, structName, fieldName) return decodeCompileUint16(typ, structName, fieldName)
case reflect.Uint32: case reflect.Uint32:
return d.compileUint32(typ, structName, fieldName) return decodeCompileUint32(typ, structName, fieldName)
case reflect.Uint64: case reflect.Uint64:
return d.compileUint64(typ, structName, fieldName) return decodeCompileUint64(typ, structName, fieldName)
case reflect.String: case reflect.String:
return d.compileString(structName, fieldName) return decodeCompileString(structName, fieldName)
case reflect.Bool: case reflect.Bool:
return d.compileBool(structName, fieldName) return decodeCompileBool(structName, fieldName)
case reflect.Float32: case reflect.Float32:
return d.compileFloat32(structName, fieldName) return decodeCompileFloat32(structName, fieldName)
case reflect.Float64: case reflect.Float64:
return d.compileFloat64(structName, fieldName) return decodeCompileFloat64(structName, fieldName)
} }
return nil, &UnmarshalTypeError{ return nil, &UnmarshalTypeError{
Value: "object", Value: "object",
@ -94,11 +93,11 @@ func (d *Decoder) compile(typ *rtype, structName, fieldName string) (decoder, er
} }
} }
func (d *Decoder) compileMapKey(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileMapKey(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
if rtype_ptrTo(typ).Implements(unmarshalTextType) { if rtype_ptrTo(typ).Implements(unmarshalTextType) {
return newUnmarshalTextDecoder(rtype_ptrTo(typ), structName, fieldName), nil return newUnmarshalTextDecoder(rtype_ptrTo(typ), structName, fieldName), nil
} }
dec, err := d.compile(typ, structName, fieldName) dec, err := decodeCompile(typ, structName, fieldName, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -122,133 +121,133 @@ ERROR:
} }
} }
func (d *Decoder) compilePtr(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompilePtr(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
dec, err := d.compile(typ.Elem(), structName, fieldName) dec, err := decodeCompile(typ.Elem(), structName, fieldName, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newPtrDecoder(dec, typ.Elem(), structName, fieldName), nil return newPtrDecoder(dec, typ.Elem(), structName, fieldName), nil
} }
func (d *Decoder) compileInt(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileInt(typ *rtype, structName, fieldName string) (decoder, error) {
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
*(*int)(p) = int(v) *(*int)(p) = int(v)
}), nil }), nil
} }
func (d *Decoder) compileInt8(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileInt8(typ *rtype, structName, fieldName string) (decoder, error) {
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
*(*int8)(p) = int8(v) *(*int8)(p) = int8(v)
}), nil }), nil
} }
func (d *Decoder) compileInt16(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileInt16(typ *rtype, structName, fieldName string) (decoder, error) {
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
*(*int16)(p) = int16(v) *(*int16)(p) = int16(v)
}), nil }), nil
} }
func (d *Decoder) compileInt32(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileInt32(typ *rtype, structName, fieldName string) (decoder, error) {
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
*(*int32)(p) = int32(v) *(*int32)(p) = int32(v)
}), nil }), nil
} }
func (d *Decoder) compileInt64(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileInt64(typ *rtype, structName, fieldName string) (decoder, error) {
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) { return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
*(*int64)(p) = v *(*int64)(p) = v
}), nil }), nil
} }
func (d *Decoder) compileUint(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileUint(typ *rtype, structName, fieldName string) (decoder, error) {
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
*(*uint)(p) = uint(v) *(*uint)(p) = uint(v)
}), nil }), nil
} }
func (d *Decoder) compileUint8(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileUint8(typ *rtype, structName, fieldName string) (decoder, error) {
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
*(*uint8)(p) = uint8(v) *(*uint8)(p) = uint8(v)
}), nil }), nil
} }
func (d *Decoder) compileUint16(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileUint16(typ *rtype, structName, fieldName string) (decoder, error) {
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
*(*uint16)(p) = uint16(v) *(*uint16)(p) = uint16(v)
}), nil }), nil
} }
func (d *Decoder) compileUint32(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileUint32(typ *rtype, structName, fieldName string) (decoder, error) {
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
*(*uint32)(p) = uint32(v) *(*uint32)(p) = uint32(v)
}), nil }), nil
} }
func (d *Decoder) compileUint64(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileUint64(typ *rtype, structName, fieldName string) (decoder, error) {
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) { return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
*(*uint64)(p) = v *(*uint64)(p) = v
}), nil }), nil
} }
func (d *Decoder) compileFloat32(structName, fieldName string) (decoder, error) { func decodeCompileFloat32(structName, fieldName string) (decoder, error) {
return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) { return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) {
*(*float32)(p) = float32(v) *(*float32)(p) = float32(v)
}), nil }), nil
} }
func (d *Decoder) compileFloat64(structName, fieldName string) (decoder, error) { func decodeCompileFloat64(structName, fieldName string) (decoder, error) {
return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) { return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) {
*(*float64)(p) = v *(*float64)(p) = v
}), nil }), nil
} }
func (d *Decoder) compileString(structName, fieldName string) (decoder, error) { func decodeCompileString(structName, fieldName string) (decoder, error) {
return newStringDecoder(structName, fieldName), nil return newStringDecoder(structName, fieldName), nil
} }
func (d *Decoder) compileBool(structName, fieldName string) (decoder, error) { func decodeCompileBool(structName, fieldName string) (decoder, error) {
return newBoolDecoder(structName, fieldName), nil return newBoolDecoder(structName, fieldName), nil
} }
func (d *Decoder) compileBytes(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileBytes(typ *rtype, structName, fieldName string) (decoder, error) {
return newBytesDecoder(typ, structName, fieldName), nil return newBytesDecoder(typ, structName, fieldName), nil
} }
func (d *Decoder) compileSlice(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileSlice(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
elem := typ.Elem() elem := typ.Elem()
decoder, err := d.compile(elem, structName, fieldName) decoder, err := decodeCompile(elem, structName, fieldName, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newSliceDecoder(decoder, elem, elem.Size(), structName, fieldName), nil return newSliceDecoder(decoder, elem, elem.Size(), structName, fieldName), nil
} }
func (d *Decoder) compileArray(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileArray(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
elem := typ.Elem() elem := typ.Elem()
decoder, err := d.compile(elem, structName, fieldName) decoder, err := decodeCompile(elem, structName, fieldName, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newArrayDecoder(decoder, elem, typ.Len(), structName, fieldName), nil return newArrayDecoder(decoder, elem, typ.Len(), structName, fieldName), nil
} }
func (d *Decoder) compileMap(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileMap(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
keyDec, err := d.compileMapKey(typ.Key(), structName, fieldName) keyDec, err := decodeCompileMapKey(typ.Key(), structName, fieldName, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
valueDec, err := d.compile(typ.Elem(), structName, fieldName) valueDec, err := decodeCompile(typ.Elem(), structName, fieldName, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return newMapDecoder(typ, typ.Key(), keyDec, typ.Elem(), valueDec, structName, fieldName), nil return newMapDecoder(typ, typ.Key(), keyDec, typ.Elem(), valueDec, structName, fieldName), nil
} }
func (d *Decoder) compileInterface(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileInterface(typ *rtype, structName, fieldName string) (decoder, error) {
return newInterfaceDecoder(d, typ, structName, fieldName), nil return newInterfaceDecoder(typ, structName, fieldName), nil
} }
func (d *Decoder) removeConflictFields(fieldMap map[string]*structFieldSet, conflictedMap map[string]struct{}, dec *structDecoder, baseOffset uintptr) { func decodeRemoveConflictFields(fieldMap map[string]*structFieldSet, conflictedMap map[string]struct{}, dec *structDecoder, baseOffset uintptr) {
for k, v := range dec.fieldMap { for k, v := range dec.fieldMap {
if _, exists := conflictedMap[k]; exists { if _, exists := conflictedMap[k]; exists {
// already conflicted key // already conflicted key
@ -303,16 +302,16 @@ func (d *Decoder) removeConflictFields(fieldMap map[string]*structFieldSet, conf
} }
} }
func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decoder, error) { func decodeCompileStruct(typ *rtype, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
fieldNum := typ.NumField() fieldNum := typ.NumField()
conflictedMap := map[string]struct{}{} conflictedMap := map[string]struct{}{}
fieldMap := map[string]*structFieldSet{} fieldMap := map[string]*structFieldSet{}
typeptr := uintptr(unsafe.Pointer(typ)) typeptr := uintptr(unsafe.Pointer(typ))
if dec, exists := d.structTypeToDecoder[typeptr]; exists { if dec, exists := structTypeToDecoder[typeptr]; exists {
return dec, nil return dec, nil
} }
structDec := newStructDecoder(structName, fieldName, fieldMap) structDec := newStructDecoder(structName, fieldName, fieldMap)
d.structTypeToDecoder[typeptr] = structDec structTypeToDecoder[typeptr] = structDec
structName = typ.Name() structName = typ.Name()
for i := 0; i < fieldNum; i++ { for i := 0; i < fieldNum; i++ {
field := typ.Field(i) field := typ.Field(i)
@ -320,7 +319,7 @@ func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decod
continue continue
} }
tag := structTagFromField(field) tag := structTagFromField(field)
dec, err := d.compile(type2rtype(field.Type), structName, field.Name) dec, err := decodeCompile(type2rtype(field.Type), structName, field.Name, structTypeToDecoder)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -330,7 +329,7 @@ func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decod
// recursive definition // recursive definition
continue continue
} }
d.removeConflictFields(fieldMap, conflictedMap, stDec, field.Offset) decodeRemoveConflictFields(fieldMap, conflictedMap, stDec, field.Offset)
} else if pdec, ok := dec.(*ptrDecoder); ok { } else if pdec, ok := dec.(*ptrDecoder); ok {
contentDec := pdec.contentDecoder() contentDec := pdec.contentDecoder()
if pdec.typ == typ { if pdec.typ == typ {
@ -416,7 +415,7 @@ func (d *Decoder) compileStruct(typ *rtype, structName, fieldName string) (decod
} }
} }
} }
delete(d.structTypeToDecoder, typeptr) delete(structTypeToDecoder, typeptr)
structDec.tryOptimize() structDec.tryOptimize()
return structDec, nil return structDec, nil
} }

View File

@ -2,9 +2,9 @@
package json package json
func (d *Decoder) compileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, error) { func decodeCompileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, error) {
if typeptr > maxTypeAddr { if typeptr > maxTypeAddr {
return d.compileToGetDecoderSlowPath(typeptr, typ) return decodeCompileToGetDecoderSlowPath(typeptr, typ)
} }
index := typeptr - baseTypeAddr index := typeptr - baseTypeAddr
@ -12,8 +12,7 @@ func (d *Decoder) compileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, err
return dec, nil return dec, nil
} }
d.structTypeToDecoder = map[uintptr]decoder{} dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
dec, err := d.compileHead(typ)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -8,9 +8,9 @@ import (
var decMu sync.RWMutex var decMu sync.RWMutex
func (d *Decoder) compileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, error) { func decodeCompileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, error) {
if typeptr > maxTypeAddr { if typeptr > maxTypeAddr {
return d.compileToGetDecoderSlowPath(typeptr, typ) return decodeCompileToGetDecoderSlowPath(typeptr, typ)
} }
index := typeptr - baseTypeAddr index := typeptr - baseTypeAddr
@ -21,8 +21,7 @@ func (d *Decoder) compileToGetDecoder(typeptr uintptr, typ *rtype) (decoder, err
} }
decMu.RUnlock() decMu.RUnlock()
d.structTypeToDecoder = map[uintptr]decoder{} dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
dec, err := d.compileHead(typ)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -10,15 +10,13 @@ type interfaceDecoder struct {
typ *rtype typ *rtype
structName string structName string
fieldName string fieldName string
dec *Decoder
} }
func newInterfaceDecoder(dec *Decoder, typ *rtype, structName, fieldName string) *interfaceDecoder { func newInterfaceDecoder(typ *rtype, structName, fieldName string) *interfaceDecoder {
return &interfaceDecoder{ return &interfaceDecoder{
typ: typ, typ: typ,
structName: structName, structName: structName,
fieldName: fieldName, fieldName: fieldName,
dec: dec,
} }
} }
@ -84,7 +82,7 @@ func (d *interfaceDecoder) decodeStreamEmptyInterface(s *stream, p unsafe.Pointe
stringType, stringType,
newStringDecoder(d.structName, d.fieldName), newStringDecoder(d.structName, d.fieldName),
interfaceMapType.Elem(), interfaceMapType.Elem(),
newInterfaceDecoder(d.dec, d.typ, d.structName, d.fieldName), newInterfaceDecoder(d.typ, d.structName, d.fieldName),
d.structName, d.structName,
d.fieldName, d.fieldName,
).decodeStream(s, ptr); err != nil { ).decodeStream(s, ptr); err != nil {
@ -96,7 +94,7 @@ func (d *interfaceDecoder) decodeStreamEmptyInterface(s *stream, p unsafe.Pointe
var v []interface{} var v []interface{}
ptr := unsafe.Pointer(&v) ptr := unsafe.Pointer(&v)
if err := newSliceDecoder( if err := newSliceDecoder(
newInterfaceDecoder(d.dec, d.typ, d.structName, d.fieldName), newInterfaceDecoder(d.typ, d.structName, d.fieldName),
d.typ, d.typ,
d.typ.Size(), d.typ.Size(),
d.structName, d.structName,
@ -190,7 +188,7 @@ func (d *interfaceDecoder) decodeStream(s *stream, p unsafe.Pointer) error {
*(*interface{})(p) = nil *(*interface{})(p) = nil
return nil return nil
} }
decoder, err := d.dec.compileToGetDecoder(uintptr(unsafe.Pointer(typ)), typ) decoder, err := decodeCompileToGetDecoder(uintptr(unsafe.Pointer(typ)), typ)
if err != nil { if err != nil {
return err return err
} }
@ -230,7 +228,7 @@ func (d *interfaceDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (i
**(**interface{})(unsafe.Pointer(&p)) = nil **(**interface{})(unsafe.Pointer(&p)) = nil
return cursor, nil return cursor, nil
} }
decoder, err := d.dec.compileToGetDecoder(uintptr(unsafe.Pointer(typ)), typ) decoder, err := decodeCompileToGetDecoder(uintptr(unsafe.Pointer(typ)), typ)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -248,7 +246,7 @@ func (d *interfaceDecoder) decodeEmptyInterface(buf []byte, cursor int64, p unsa
stringType, stringType,
newStringDecoder(d.structName, d.fieldName), newStringDecoder(d.structName, d.fieldName),
interfaceMapType.Elem(), interfaceMapType.Elem(),
newInterfaceDecoder(d.dec, d.typ, d.structName, d.fieldName), newInterfaceDecoder(d.typ, d.structName, d.fieldName),
d.structName, d.fieldName, d.structName, d.fieldName,
) )
cursor, err := dec.decode(buf, cursor, ptr) cursor, err := dec.decode(buf, cursor, ptr)
@ -261,7 +259,7 @@ func (d *interfaceDecoder) decodeEmptyInterface(buf []byte, cursor int64, p unsa
var v []interface{} var v []interface{}
ptr := unsafe.Pointer(&v) ptr := unsafe.Pointer(&v)
dec := newSliceDecoder( dec := newSliceDecoder(
newInterfaceDecoder(d.dec, d.typ, d.structName, d.fieldName), newInterfaceDecoder(d.typ, d.structName, d.fieldName),
d.typ, d.typ,
d.typ.Size(), d.typ.Size(),
d.structName, d.fieldName, d.structName, d.fieldName,