From f88163d80ffc3ac7d84177e1c2fabd9811abfe66 Mon Sep 17 00:00:00 2001 From: Juan Pablo Tosso Date: Tue, 31 Oct 2023 10:30:08 +0100 Subject: [PATCH] prealloc --- internal/corazawaf/transaction.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/corazawaf/transaction.go b/internal/corazawaf/transaction.go index 5451b59aa..2a1197d22 100644 --- a/internal/corazawaf/transaction.go +++ b/internal/corazawaf/transaction.go @@ -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 @@ -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)