From 6936195afac72d947a69bb300c3b2d0a6dba040a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 28 Mar 2022 16:15:42 +0300 Subject: [PATCH] [#1239] util/attributes: Remove excessive slice copy during parsing Signed-off-by: Evgenii Stratonikov --- pkg/util/attributes/parser.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/util/attributes/parser.go b/pkg/util/attributes/parser.go index a3660c62d..2af03486c 100644 --- a/pkg/util/attributes/parser.go +++ b/pkg/util/attributes/parser.go @@ -28,7 +28,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]netmap.NodeAttribute, e } cache := make(map[string]*netmap.NodeAttribute, len(attrs)) - result := make([]*netmap.NodeAttribute, 0, len(attrs)) + result := make([]netmap.NodeAttribute, 0, len(attrs)) for i := range attrs { line := strings.Trim(attrs[i], pairSeparator) @@ -59,9 +59,9 @@ func ParseV2Attributes(attrs []string, excl []string) ([]netmap.NodeAttribute, e } if !present { - attribute = netmap.NewNodeAttribute() + result = append(result, netmap.NodeAttribute{}) + attribute = &result[len(result)-1] cache[key] = attribute - result = append(result, attribute) // replace non-printable symbols with escaped symbols without escape character key = replaceEscaping(key, true) @@ -82,12 +82,7 @@ func ParseV2Attributes(attrs []string, excl []string) ([]netmap.NodeAttribute, e } } - nresult := make([]netmap.NodeAttribute, len(result)) - for i := range result { - nresult[i] = *result[i] - } - - return nresult, nil + return result, nil } func replaceEscaping(target string, rollback bool) (s string) {