[FEAT] Add geodata loader mode switch

This commit is contained in:
gVisor bot 2022-02-05 02:42:49 +08:00
parent e3a61dbbd3
commit b75e8f9500
3 changed files with 15 additions and 13 deletions

View file

@ -12,6 +12,7 @@ import (
"regexp"
"runtime"
"strings"
"time"
"github.com/Dreamacro/clash/adapter"
"github.com/Dreamacro/clash/adapter/outbound"
@ -309,7 +310,7 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
func parseGeneral(cfg *RawConfig) (*General, error) {
externalUI := cfg.ExternalUI
geodata.SetLoader(cfg.GeodataLoader)
// checkout externalUI exist
if externalUI != "" {
externalUI = C.Path.Resolve(externalUI)
@ -339,6 +340,7 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
LogLevel: cfg.LogLevel,
IPv6: cfg.IPv6,
Interface: cfg.Interface,
GeodataLoader: cfg.GeodataLoader,
}, nil
}
@ -486,6 +488,7 @@ time = ClashTime()
func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[string]*providerTypes.RuleProvider, error) {
ruleProviders := map[string]*providerTypes.RuleProvider{}
startTime := time.Now()
// parse rule provider
for name, mapping := range cfg.RuleProvider {
rp, err := RP.ParseRuleProvider(name, mapping)
@ -560,7 +563,9 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin
rules = append(rules, parsed)
}
}
elapsedTime := time.Since(startTime) / time.Millisecond // duration in ms
log.Infoln("Initialization time consuming %dms", elapsedTime) //Segment finished in xxm
log.Infoln("Geodata Loader mode: %s", geodata.LoaderName())
runtime.GC()
return rules, ruleProviders, nil

View file

@ -78,11 +78,11 @@ func ApplyConfig(cfg *config.Config, force bool) {
updateUsers(cfg.Users)
updateHosts(cfg.Hosts)
updateGeneral(cfg.General, cfg.Tun, force)
updateProxies(cfg.Proxies, cfg.Providers)
updateRules(cfg.Rules, cfg.RuleProviders)
updateIPTables(cfg.DNS, cfg.General, cfg.Tun)
updateDNS(cfg.DNS, cfg.Tun)
updateGeneral(cfg.General, cfg.Tun, force)
updateTun(cfg.Tun)
updateExperimental(cfg)
loadProvider(cfg.RuleProviders, cfg.Providers)
@ -242,9 +242,6 @@ func updateGeneral(general *config.General, Tun *config.Tun, force bool) {
return
}
geodataLoader := general.GeodataLoader
G.SetLoader(geodataLoader)
allowLan := general.AllowLan
P.SetAllowLan(allowLan)