mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-29 18:38:56 +03:00
Generalise a construct to simplify a function
This commit is contained in:
parent
bdff46ec1d
commit
6a09acc262
1 changed files with 11 additions and 9 deletions
|
@ -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]
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue