Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: use map iter to iterate the map instead of map keys and values #3457

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading