Skip to content

Commit

Permalink
Remove append, use simple allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
soujanyanmbri committed Nov 7, 2024
1 parent 6c15ec9 commit 8ee2395
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/collections/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8ee2395

Please sign in to comment.