refactor: optimize the performance of filter in proxy-group

This commit is contained in:
adlyq
2022-04-28 19:01:13 +08:00
parent 8217db82ce
commit f1dab9e9ce
8 changed files with 182 additions and 117 deletions

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/dlclark/regexp2"
"math"
"runtime"
"time"
@ -32,6 +33,11 @@ type proxySetProvider struct {
*fetcher
proxies []C.Proxy
healthCheck *HealthCheck
flag uint
}
func (pp *proxySetProvider) Flag() uint {
return pp.flag
}
func (pp *proxySetProvider) MarshalJSON() ([]byte, error) {
@ -117,6 +123,11 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, veh
onUpdate := func(elm any) {
ret := elm.([]C.Proxy)
pd.setProxies(ret)
if pd.flag == math.MaxUint {
pd.flag = 0
} else {
pd.flag++
}
}
proxiesParseAndFilter := func(buf []byte) (any, error) {
@ -171,6 +182,11 @@ type compatibleProvider struct {
name string
healthCheck *HealthCheck
proxies []C.Proxy
flag uint
}
func (cp *compatibleProvider) Flag() uint {
return cp.flag
}
func (cp *compatibleProvider) MarshalJSON() ([]byte, error) {