Fix mapassign

This commit is contained in:
Masaaki Goshima 2021-08-30 11:40:10 +09:00
parent 8f5f28614c
commit 284c108638
1 changed files with 21 additions and 18 deletions

View File

@ -12,7 +12,7 @@ type mapDecoder struct {
mapType *runtime.Type
keyType *runtime.Type
valueType *runtime.Type
stringKeyType bool
canUseAssignFaststrType bool
keyDecoder Decoder
valueDecoder Decoder
structName string
@ -20,11 +20,14 @@ type mapDecoder struct {
}
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{
mapType: mapType,
keyDecoder: keyDec,
keyType: keyType,
stringKeyType: keyType.Kind() == reflect.String,
canUseAssignFaststrType: canUseAssignFaststrType,
valueType: valueType,
valueDecoder: valueDec,
structName: structName,
@ -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 (d *mapDecoder) mapassign(t *runtime.Type, m, k, v unsafe.Pointer) {
if d.stringKeyType {
mapV := mapassign_faststr(d.mapType, m, *(*string)(k))
if d.canUseAssignFaststrType {
mapV := mapassign_faststr(t, m, *(*string)(k))
typedmemmove(d.valueType, mapV, v)
} else {
mapassign(t, m, k, v)