Skip to content

Commit be9523a

Browse files
committed
optimize Pattern.WeakEqual
1 parent 39110d8 commit be9523a

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

pattern.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
)
1010

1111
const (
12-
minWordLen = 2
12+
minWordLen = 2
13+
patternMaxDiff = 1
14+
patternCheckFirstN = 100
1315
)
1416

1517
var (
@@ -54,10 +56,13 @@ func (p *Pattern) WeakEqual(other *Pattern) bool {
5456
return false
5557
}
5658
var diffs int
57-
for i, ow := range other.words {
58-
if p.words[i] != ow {
59+
for i := range other.words {
60+
if i > patternCheckFirstN {
61+
return true
62+
}
63+
if p.words[i] != other.words[i] {
5964
diffs++
60-
if diffs > 1 {
65+
if diffs > patternMaxDiff {
6166
return false
6267
}
6368
}

0 commit comments

Comments
 (0)