mirror of https://github.com/goccy/go-json.git
Remove unnecessary prefix
This commit is contained in:
parent
5a024ca2f1
commit
de4e97ed09
|
@ -44,13 +44,13 @@ func storeDecoder(typ uintptr, dec decoder, m map[uintptr]decoder) {
|
|||
atomic.StorePointer(&cachedDecoderMap, *(*unsafe.Pointer)(unsafe.Pointer(&newDecoderMap)))
|
||||
}
|
||||
|
||||
func decodeCompileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (decoder, error) {
|
||||
func compileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (decoder, error) {
|
||||
decoderMap := loadDecoderMap()
|
||||
if dec, exists := decoderMap[typeptr]; exists {
|
||||
return dec, nil
|
||||
}
|
||||
|
||||
dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
|
||||
dec, err := compileHead(typ, map[uintptr]decoder{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -58,17 +58,17 @@ func decodeCompileToGetDecoderSlowPath(typeptr uintptr, typ *runtime.Type) (deco
|
|||
return dec, nil
|
||||
}
|
||||
|
||||
func decodeCompileHead(typ *runtime.Type, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
func compileHead(typ *runtime.Type, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
switch {
|
||||
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
||||
return newUnmarshalJSONDecoder(runtime.PtrTo(typ), "", ""), nil
|
||||
case runtime.PtrTo(typ).Implements(unmarshalTextType):
|
||||
return newUnmarshalTextDecoder(runtime.PtrTo(typ), "", ""), nil
|
||||
}
|
||||
return decodeCompile(typ.Elem(), "", "", structTypeToDecoder)
|
||||
return compile(typ.Elem(), "", "", structTypeToDecoder)
|
||||
}
|
||||
|
||||
func decodeCompile(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
func compile(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
switch {
|
||||
case runtime.PtrTo(typ).Implements(unmarshalJSONType):
|
||||
return newUnmarshalJSONDecoder(runtime.PtrTo(typ), structName, fieldName), nil
|
||||
|
@ -78,51 +78,51 @@ func decodeCompile(typ *runtime.Type, structName, fieldName string, structTypeTo
|
|||
|
||||
switch typ.Kind() {
|
||||
case reflect.Ptr:
|
||||
return decodeCompilePtr(typ, structName, fieldName, structTypeToDecoder)
|
||||
return compilePtr(typ, structName, fieldName, structTypeToDecoder)
|
||||
case reflect.Struct:
|
||||
return decodeCompileStruct(typ, structName, fieldName, structTypeToDecoder)
|
||||
return compileStruct(typ, structName, fieldName, structTypeToDecoder)
|
||||
case reflect.Slice:
|
||||
elem := typ.Elem()
|
||||
if elem.Kind() == reflect.Uint8 {
|
||||
return decodeCompileBytes(elem, structName, fieldName)
|
||||
return compileBytes(elem, structName, fieldName)
|
||||
}
|
||||
return decodeCompileSlice(typ, structName, fieldName, structTypeToDecoder)
|
||||
return compileSlice(typ, structName, fieldName, structTypeToDecoder)
|
||||
case reflect.Array:
|
||||
return decodeCompileArray(typ, structName, fieldName, structTypeToDecoder)
|
||||
return compileArray(typ, structName, fieldName, structTypeToDecoder)
|
||||
case reflect.Map:
|
||||
return decodeCompileMap(typ, structName, fieldName, structTypeToDecoder)
|
||||
return compileMap(typ, structName, fieldName, structTypeToDecoder)
|
||||
case reflect.Interface:
|
||||
return decodeCompileInterface(typ, structName, fieldName)
|
||||
return compileInterface(typ, structName, fieldName)
|
||||
case reflect.Uintptr:
|
||||
return decodeCompileUint(typ, structName, fieldName)
|
||||
return compileUint(typ, structName, fieldName)
|
||||
case reflect.Int:
|
||||
return decodeCompileInt(typ, structName, fieldName)
|
||||
return compileInt(typ, structName, fieldName)
|
||||
case reflect.Int8:
|
||||
return decodeCompileInt8(typ, structName, fieldName)
|
||||
return compileInt8(typ, structName, fieldName)
|
||||
case reflect.Int16:
|
||||
return decodeCompileInt16(typ, structName, fieldName)
|
||||
return compileInt16(typ, structName, fieldName)
|
||||
case reflect.Int32:
|
||||
return decodeCompileInt32(typ, structName, fieldName)
|
||||
return compileInt32(typ, structName, fieldName)
|
||||
case reflect.Int64:
|
||||
return decodeCompileInt64(typ, structName, fieldName)
|
||||
return compileInt64(typ, structName, fieldName)
|
||||
case reflect.Uint:
|
||||
return decodeCompileUint(typ, structName, fieldName)
|
||||
return compileUint(typ, structName, fieldName)
|
||||
case reflect.Uint8:
|
||||
return decodeCompileUint8(typ, structName, fieldName)
|
||||
return compileUint8(typ, structName, fieldName)
|
||||
case reflect.Uint16:
|
||||
return decodeCompileUint16(typ, structName, fieldName)
|
||||
return compileUint16(typ, structName, fieldName)
|
||||
case reflect.Uint32:
|
||||
return decodeCompileUint32(typ, structName, fieldName)
|
||||
return compileUint32(typ, structName, fieldName)
|
||||
case reflect.Uint64:
|
||||
return decodeCompileUint64(typ, structName, fieldName)
|
||||
return compileUint64(typ, structName, fieldName)
|
||||
case reflect.String:
|
||||
return decodeCompileString(typ, structName, fieldName)
|
||||
return compileString(typ, structName, fieldName)
|
||||
case reflect.Bool:
|
||||
return decodeCompileBool(structName, fieldName)
|
||||
return compileBool(structName, fieldName)
|
||||
case reflect.Float32:
|
||||
return decodeCompileFloat32(structName, fieldName)
|
||||
return compileFloat32(structName, fieldName)
|
||||
case reflect.Float64:
|
||||
return decodeCompileFloat64(structName, fieldName)
|
||||
return compileFloat64(structName, fieldName)
|
||||
}
|
||||
return nil, &errors.UnmarshalTypeError{
|
||||
Value: "object",
|
||||
|
@ -153,11 +153,11 @@ func isStringTagSupportedType(typ *runtime.Type) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func decodeCompileMapKey(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
func compileMapKey(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
if runtime.PtrTo(typ).Implements(unmarshalTextType) {
|
||||
return newUnmarshalTextDecoder(runtime.PtrTo(typ), structName, fieldName), nil
|
||||
}
|
||||
dec, err := decodeCompile(typ, structName, fieldName, structTypeToDecoder)
|
||||
dec, err := compile(typ, structName, fieldName, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -181,87 +181,87 @@ ERROR:
|
|||
}
|
||||
}
|
||||
|
||||
func decodeCompilePtr(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
dec, err := decodeCompile(typ.Elem(), structName, fieldName, structTypeToDecoder)
|
||||
func compilePtr(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
dec, err := compile(typ.Elem(), structName, fieldName, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newPtrDecoder(dec, typ.Elem(), structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileInt(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileInt(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||
*(*int)(p) = int(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileInt8(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileInt8(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||
*(*int8)(p) = int8(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileInt16(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileInt16(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||
*(*int16)(p) = int16(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileInt32(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileInt32(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||
*(*int32)(p) = int32(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileInt64(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileInt64(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newIntDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v int64) {
|
||||
*(*int64)(p) = v
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileUint(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileUint(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||
*(*uint)(p) = uint(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileUint8(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileUint8(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||
*(*uint8)(p) = uint8(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileUint16(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileUint16(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||
*(*uint16)(p) = uint16(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileUint32(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileUint32(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||
*(*uint32)(p) = uint32(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileUint64(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileUint64(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newUintDecoder(typ, structName, fieldName, func(p unsafe.Pointer, v uint64) {
|
||||
*(*uint64)(p) = v
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileFloat32(structName, fieldName string) (decoder, error) {
|
||||
func compileFloat32(structName, fieldName string) (decoder, error) {
|
||||
return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) {
|
||||
*(*float32)(p) = float32(v)
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileFloat64(structName, fieldName string) (decoder, error) {
|
||||
func compileFloat64(structName, fieldName string) (decoder, error) {
|
||||
return newFloatDecoder(structName, fieldName, func(p unsafe.Pointer, v float64) {
|
||||
*(*float64)(p) = v
|
||||
}), nil
|
||||
}
|
||||
|
||||
func decodeCompileString(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileString(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
if typ == runtime.Type2RType(jsonNumberType) {
|
||||
return newNumberDecoder(structName, fieldName, func(p unsafe.Pointer, v json.Number) {
|
||||
*(*json.Number)(p) = v
|
||||
|
@ -270,49 +270,49 @@ func decodeCompileString(typ *runtime.Type, structName, fieldName string) (decod
|
|||
return newStringDecoder(structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileBool(structName, fieldName string) (decoder, error) {
|
||||
func compileBool(structName, fieldName string) (decoder, error) {
|
||||
return newBoolDecoder(structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileBytes(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileBytes(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newBytesDecoder(typ, structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileSlice(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
func compileSlice(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
elem := typ.Elem()
|
||||
decoder, err := decodeCompile(elem, structName, fieldName, structTypeToDecoder)
|
||||
decoder, err := compile(elem, structName, fieldName, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newSliceDecoder(decoder, elem, elem.Size(), structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileArray(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
func compileArray(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
elem := typ.Elem()
|
||||
decoder, err := decodeCompile(elem, structName, fieldName, structTypeToDecoder)
|
||||
decoder, err := compile(elem, structName, fieldName, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newArrayDecoder(decoder, elem, typ.Len(), structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileMap(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
keyDec, err := decodeCompileMapKey(typ.Key(), structName, fieldName, structTypeToDecoder)
|
||||
func compileMap(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
keyDec, err := compileMapKey(typ.Key(), structName, fieldName, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueDec, err := decodeCompile(typ.Elem(), structName, fieldName, structTypeToDecoder)
|
||||
valueDec, err := compile(typ.Elem(), structName, fieldName, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return newMapDecoder(typ, typ.Key(), keyDec, typ.Elem(), valueDec, structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeCompileInterface(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
func compileInterface(typ *runtime.Type, structName, fieldName string) (decoder, error) {
|
||||
return newInterfaceDecoder(typ, structName, fieldName), nil
|
||||
}
|
||||
|
||||
func decodeRemoveConflictFields(fieldMap map[string]*structFieldSet, conflictedMap map[string]struct{}, dec *structDecoder, field reflect.StructField) {
|
||||
func removeConflictFields(fieldMap map[string]*structFieldSet, conflictedMap map[string]struct{}, dec *structDecoder, field reflect.StructField) {
|
||||
for k, v := range dec.fieldMap {
|
||||
if _, exists := conflictedMap[k]; exists {
|
||||
// already conflicted key
|
||||
|
@ -367,7 +367,7 @@ func decodeRemoveConflictFields(fieldMap map[string]*structFieldSet, conflictedM
|
|||
}
|
||||
}
|
||||
|
||||
func decodeCompileStruct(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
func compileStruct(typ *runtime.Type, structName, fieldName string, structTypeToDecoder map[uintptr]decoder) (decoder, error) {
|
||||
fieldNum := typ.NumField()
|
||||
conflictedMap := map[string]struct{}{}
|
||||
fieldMap := map[string]*structFieldSet{}
|
||||
|
@ -385,7 +385,7 @@ func decodeCompileStruct(typ *runtime.Type, structName, fieldName string, struct
|
|||
}
|
||||
isUnexportedField := unicode.IsLower([]rune(field.Name)[0])
|
||||
tag := runtime.StructTagFromField(field)
|
||||
dec, err := decodeCompile(runtime.Type2RType(field.Type), structName, field.Name, structTypeToDecoder)
|
||||
dec, err := compile(runtime.Type2RType(field.Type), structName, field.Name, structTypeToDecoder)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ func decodeCompileStruct(typ *runtime.Type, structName, fieldName string, struct
|
|||
// recursive definition
|
||||
continue
|
||||
}
|
||||
decodeRemoveConflictFields(fieldMap, conflictedMap, stDec, field)
|
||||
removeConflictFields(fieldMap, conflictedMap, stDec, field)
|
||||
} else if pdec, ok := dec.(*ptrDecoder); ok {
|
||||
contentDec := pdec.contentDecoder()
|
||||
if pdec.typ == typ {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
||||
typeptr := uintptr(unsafe.Pointer(typ))
|
||||
if typeptr > typeAddr.MaxTypeAddr {
|
||||
return decodeCompileToGetDecoderSlowPath(typeptr, typ)
|
||||
return compileToGetDecoderSlowPath(typeptr, typ)
|
||||
}
|
||||
|
||||
index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift
|
||||
|
@ -19,7 +19,7 @@ func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
|||
return dec, nil
|
||||
}
|
||||
|
||||
dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
|
||||
dec, err := compileHead(typ, map[uintptr]decoder{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ var decMu sync.RWMutex
|
|||
|
||||
func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
||||
typeptr := uintptr(unsafe.Pointer(typ))
|
||||
if typeptr > maxTypeAddr {
|
||||
return decodeCompileToGetDecoderSlowPath(typeptr, typ)
|
||||
if typeptr > typeAddr.MaxTypeAddr {
|
||||
return compileToGetDecoderSlowPath(typeptr, typ)
|
||||
}
|
||||
|
||||
index := (typeptr - baseTypeAddr) >> typeAddrShift
|
||||
index := (typeptr - typeAddr.BaseTypeAddr) >> typeAddr.AddrShift
|
||||
decMu.RLock()
|
||||
if dec := cachedDecoder[index]; dec != nil {
|
||||
decMu.RUnlock()
|
||||
|
@ -25,7 +25,7 @@ func CompileToGetDecoder(typ *runtime.Type) (decoder, error) {
|
|||
}
|
||||
decMu.RUnlock()
|
||||
|
||||
dec, err := decodeCompileHead(typ, map[uintptr]decoder{})
|
||||
dec, err := compileHead(typ, map[uintptr]decoder{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue