diff --git a/app/router/condition.go b/app/router/condition.go index ea09a560..1d43e536 100644 --- a/app/router/condition.go +++ b/app/router/condition.go @@ -83,21 +83,6 @@ func NewMphMatcherGroup(domains []*Domain) (*DomainMatcher, error) { }, nil } -func NewDomainMatcher(domains []*Domain) (*DomainMatcher, error) { - g := new(strmatcher.MatcherGroup) - for _, d := range domains { - m, err := domainToMatcher(d) - if err != nil { - return nil, err - } - g.Add(m) - } - - return &DomainMatcher{ - matchers: g, - }, nil -} - func (m *DomainMatcher) ApplyDomain(domain string) bool { return len(m.matchers.Match(strings.ToLower(domain))) > 0 } diff --git a/app/router/condition_test.go b/app/router/condition_test.go index a5e54770..7e90351a 100644 --- a/app/router/condition_test.go +++ b/app/router/condition_test.go @@ -328,9 +328,6 @@ func TestChinaSites(t *testing.T) { domains, err := loadGeoSite("CN") common.Must(err) - matcher, err := NewDomainMatcher(domains) - common.Must(err) - acMatcher, err := NewMphMatcherGroup(domains) common.Must(err) @@ -362,12 +359,9 @@ func TestChinaSites(t *testing.T) { } for _, testCase := range testCases { - r1 := matcher.ApplyDomain(testCase.Domain) - r2 := acMatcher.ApplyDomain(testCase.Domain) - if r1 != testCase.Output { - t.Error("DomainMatcher expected output ", testCase.Output, " for domain ", testCase.Domain, " but got ", r1) - } else if r2 != testCase.Output { - t.Error("ACDomainMatcher expected output ", testCase.Output, " for domain ", testCase.Domain, " but got ", r2) + r := acMatcher.ApplyDomain(testCase.Domain) + if r != testCase.Output { + t.Error("ACDomainMatcher expected output ", testCase.Output, " for domain ", testCase.Domain, " but got ", r) } } } @@ -414,48 +408,6 @@ func BenchmarkMphDomainMatcher(b *testing.B) { } } -func BenchmarkDomainMatcher(b *testing.B) { - domains, err := loadGeoSite("CN") - common.Must(err) - - matcher, err := NewDomainMatcher(domains) - common.Must(err) - - type TestCase struct { - Domain string - Output bool - } - testCases := []TestCase{ - { - Domain: "163.com", - Output: true, - }, - { - Domain: "163.com", - Output: true, - }, - { - Domain: "164.com", - Output: false, - }, - { - Domain: "164.com", - Output: false, - }, - } - - for i := 0; i < 1024; i++ { - testCases = append(testCases, TestCase{Domain: strconv.Itoa(i) + ".not-exists.com", Output: false}) - } - - b.ResetTimer() - for i := 0; i < b.N; i++ { - for _, testCase := range testCases { - _ = matcher.ApplyDomain(testCase.Domain) - } - } -} - func BenchmarkMultiGeoIPMatcher(b *testing.B) { var geoips []*GeoIP