From 714ef5c563b79595281a0c844a295b90fc9dcdcc Mon Sep 17 00:00:00 2001 From: Fabrice Vaillant Date: Fri, 17 Jan 2025 10:06:48 +0100 Subject: [PATCH] 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 --- mapstructure.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapstructure.go b/mapstructure.go index e77e63ba..56c749bf 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1434,8 +1434,8 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e if tagValue == "" && d.config.IgnoreUntaggedFields { continue } - tagValue = strings.SplitN(tagValue, ",", 2)[0] if tagValue != "" { + tagValue, _, _ = strings.Cut(tagValue, ",") fieldName = tagValue }