mirror of https://github.com/goccy/go-json.git
Fix mapassign
This commit is contained in:
parent
8f5f28614c
commit
284c108638
|
@ -9,26 +9,29 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type mapDecoder struct {
|
type mapDecoder struct {
|
||||||
mapType *runtime.Type
|
mapType *runtime.Type
|
||||||
keyType *runtime.Type
|
keyType *runtime.Type
|
||||||
valueType *runtime.Type
|
valueType *runtime.Type
|
||||||
stringKeyType bool
|
canUseAssignFaststrType bool
|
||||||
keyDecoder Decoder
|
keyDecoder Decoder
|
||||||
valueDecoder Decoder
|
valueDecoder Decoder
|
||||||
structName string
|
structName string
|
||||||
fieldName string
|
fieldName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMapDecoder(mapType *runtime.Type, keyType *runtime.Type, keyDec Decoder, valueType *runtime.Type, valueDec Decoder, structName, fieldName string) *mapDecoder {
|
func newMapDecoder(mapType *runtime.Type, keyType *runtime.Type, keyDec Decoder, valueType *runtime.Type, valueDec Decoder, structName, fieldName string) *mapDecoder {
|
||||||
|
isStructIndirect := valueType.Kind() == reflect.Struct && runtime.IfaceIndir(valueType)
|
||||||
|
stringKeyType := keyType.Kind() == reflect.String
|
||||||
|
canUseAssignFaststrType := stringKeyType && !isStructIndirect
|
||||||
return &mapDecoder{
|
return &mapDecoder{
|
||||||
mapType: mapType,
|
mapType: mapType,
|
||||||
keyDecoder: keyDec,
|
keyDecoder: keyDec,
|
||||||
keyType: keyType,
|
keyType: keyType,
|
||||||
stringKeyType: keyType.Kind() == reflect.String,
|
canUseAssignFaststrType: canUseAssignFaststrType,
|
||||||
valueType: valueType,
|
valueType: valueType,
|
||||||
valueDecoder: valueDec,
|
valueDecoder: valueDec,
|
||||||
structName: structName,
|
structName: structName,
|
||||||
fieldName: fieldName,
|
fieldName: fieldName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +48,8 @@ func mapassign_faststr(t *runtime.Type, m unsafe.Pointer, s string) unsafe.Point
|
||||||
func mapassign(t *runtime.Type, m unsafe.Pointer, k, v unsafe.Pointer)
|
func mapassign(t *runtime.Type, m unsafe.Pointer, k, v unsafe.Pointer)
|
||||||
|
|
||||||
func (d *mapDecoder) mapassign(t *runtime.Type, m, k, v unsafe.Pointer) {
|
func (d *mapDecoder) mapassign(t *runtime.Type, m, k, v unsafe.Pointer) {
|
||||||
if d.stringKeyType {
|
if d.canUseAssignFaststrType {
|
||||||
mapV := mapassign_faststr(d.mapType, m, *(*string)(k))
|
mapV := mapassign_faststr(t, m, *(*string)(k))
|
||||||
typedmemmove(d.valueType, mapV, v)
|
typedmemmove(d.valueType, mapV, v)
|
||||||
} else {
|
} else {
|
||||||
mapassign(t, m, k, v)
|
mapassign(t, m, k, v)
|
||||||
|
|
Loading…
Reference in New Issue