From 8ee2395ab4412a1fbe9eed42a72009746326fec1 Mon Sep 17 00:00:00 2001 From: soujanyanmbri <54130357+soujanyanmbri@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:22:03 +0530 Subject: [PATCH] Remove append, use simple allocation --- internal/collections/map.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/collections/map.go b/internal/collections/map.go index e2c83104c..5ae16b4ec 100644 --- a/internal/collections/map.go +++ b/internal/collections/map.go @@ -41,17 +41,18 @@ func NewCaseSensitiveKeyMap(variable variables.RuleVariable) *Map { } func (c *Map) Get(key string) []string { - if len(c.data) == 0 { - return nil - } if !c.isCaseSensitive { key = strings.ToLower(key) } - var values []string - for _, a := range c.data[key] { - values = append(values, a.value) + values := c.data[key] + if len(values) == 0 { + return nil + } + result := make([]string, 0, len(values)) + for _, a := range values { + result = append(result, a.value) } - return values + return result } // FindRegex returns all map elements whose key matches the regular expression.