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.