Skip to content

Commit

Permalink
Favor strings.Cut to strings.SplitN
Browse files Browse the repository at this point in the history
It is more efficient since it does not allocate an array and just return
s if nothing found

For the same reason we don't need to use  strings.Cut at all if empty
  • Loading branch information
Fabrice Vaillant committed Jan 17, 2025
1 parent 8508981 commit 67d7e69
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mapstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,8 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
fieldName := field.Name

tagValue := field.Tag.Get(d.config.TagName)
tagValue = strings.SplitN(tagValue, ",", 2)[0]
if tagValue != "" {
tagValue, _, _ = strings.Cut(tagValue, ",")
fieldName = tagValue
}

Expand Down

0 comments on commit 67d7e69

Please sign in to comment.