Generalise a construct to simplify a function

This commit is contained in:
jvoisin 2020-12-22 16:43:47 +01:00
parent bdff46ec1d
commit 6a09acc262

View file

@ -122,21 +122,23 @@ func findRewrites(a []RewriteEntry, host string) []RewriteEntry {
sort.Sort(rr)
isWC := isWildcard(rr[0].Domain)
if !isWC {
for i, r := range rr {
if isWildcard(r.Domain) {
rr = rr[:i]
break
}
for i, r := range rr {
if isWildcard(r.Domain) {
rr = rr[:max(1, i)]
break
}
} else {
rr = rr[:1]
}
return rr
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func rewriteArrayDup(a []RewriteEntry) []RewriteEntry {
a2 := make([]RewriteEntry, len(a))
copy(a2, a)