Skip to content

Commit 50933f3

Browse files
authored
Refactor: matcher use min (#3901)
Refactor: matcher use min --------- Signed-off-by: Sandor Szücs <[email protected]>
1 parent 77b2dbb commit 50933f3

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

routing/matcher.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77
"regexp"
8+
"slices"
89
"sort"
910
"strings"
1011

@@ -369,10 +370,7 @@ func matchPathTree(tree *pathmux.Tree, path string, lrm *leafRequestMatcher) (ma
369370
params = append([]string{""}, params...)
370371
}
371372

372-
l := len(params)
373-
if l > len(lm.wildcardParamNames) {
374-
l = len(lm.wildcardParamNames)
375-
}
373+
l := min(len(params), len(lm.wildcardParamNames))
376374

377375
paramsMap := make(map[string]string)
378376
for i := 0; i < l; i += 1 {
@@ -403,13 +401,7 @@ func matchHeader(h http.Header, key string, check func(string) bool) bool {
403401
return false
404402
}
405403

406-
for _, val := range vals {
407-
if check(val) {
408-
return true
409-
}
410-
}
411-
412-
return false
404+
return slices.ContainsFunc(vals, check)
413405
}
414406

415407
// matches a set of request headers to the fix and regexp header conditions

0 commit comments

Comments
 (0)