Skip to content

Commit

Permalink
enhance: use map iter to iterate the map instead of map keys and valu…
Browse files Browse the repository at this point in the history
…es (#3457)
  • Loading branch information
wln32 committed Apr 7, 2024
1 parent 1b7aea0 commit 911f1cb
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions util/gconv/gconv_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,12 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
switch reflectKind {
case reflect.Map:
var (
mapKeys = reflectValue.MapKeys()
mapIter = reflectValue.MapRange()
dataMap = make(map[string]interface{})
)
for _, k := range mapKeys {
for mapIter.Next() {
var (
mapKeyValue = reflectValue.MapIndex(k)
mapKeyValue = mapIter.Value()
mapValue interface{}
)
switch {
Expand All @@ -319,7 +319,7 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
default:
mapValue = mapKeyValue.Interface()
}
dataMap[String(k.Interface())] = doMapConvertForMapOrStructValue(
dataMap[String(mapIter.Key().Interface())] = doMapConvertForMapOrStructValue(
doMapConvertForMapOrStructValueInput{
IsRoot: false,
Value: mapValue,
Expand Down Expand Up @@ -486,14 +486,14 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
dataMap[mapKey] = array
case reflect.Map:
var (
mapKeys = rvAttrField.MapKeys()
mapIter = rvAttrField.MapRange()
nestedMap = make(map[string]interface{})
)
for _, k := range mapKeys {
nestedMap[String(k.Interface())] = doMapConvertForMapOrStructValue(
for mapIter.Next() {
nestedMap[String(mapIter.Key().Interface())] = doMapConvertForMapOrStructValue(
doMapConvertForMapOrStructValueInput{
IsRoot: false,
Value: rvAttrField.MapIndex(k).Interface(),
Value: mapIter.Value().Interface(),
RecursiveType: in.RecursiveType,
RecursiveOption: in.RecursiveType == recursiveTypeTrue,
Option: in.Option,
Expand Down

0 comments on commit 911f1cb

Please sign in to comment.