Skip to content

Commit

Permalink
prealloc
Browse files Browse the repository at this point in the history
  • Loading branch information
jptosso committed Oct 31, 2023
1 parent e1a276c commit f88163d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions internal/corazawaf/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,7 @@ func (tx *Transaction) GetField(rv ruleVariableParams) []types.MatchData {

// in the most common scenario filteredMatches length will be
// the same as matches length, so we avoid allocating per result
filteredMatches := make([]types.MatchData, len(matches))
filteredCount := 0
filteredMatches := make([]types.MatchData, 0, len(matches))

for _, c := range matches {
isException := false
Expand All @@ -576,11 +575,10 @@ func (tx *Transaction) GetField(rv ruleVariableParams) []types.MatchData {
}
}
if !isException {
filteredMatches[filteredCount] = c
filteredCount++
filteredMatches = append(filteredMatches, c)
}
}
matches = filteredMatches[:filteredCount]
matches = filteredMatches

if rv.Count {
count := len(matches)
Expand Down

0 comments on commit f88163d

Please sign in to comment.