Skip to content

Commit 714ef5c

Browse files
author
Fabrice Vaillant
committed
Favor strings.Cut to strings.SplitN
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
1 parent 7aa50a4 commit 714ef5c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

mapstructure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,8 +1434,8 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e
14341434
if tagValue == "" && d.config.IgnoreUntaggedFields {
14351435
continue
14361436
}
1437-
tagValue = strings.SplitN(tagValue, ",", 2)[0]
14381437
if tagValue != "" {
1438+
tagValue, _, _ = strings.Cut(tagValue, ",")
14391439
fieldName = tagValue
14401440
}
14411441

0 commit comments

Comments
 (0)