File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change 99)
1010
1111const (
12- minWordLen = 2
13- patternMaxDiff = 1
14- patternCheckFirstN = 100
12+ patternMaxWords = 100
13+ patterMinWordLen = 2
14+ patternMaxDiff = 1
1515)
1616
1717var (
@@ -57,9 +57,6 @@ func (p *Pattern) WeakEqual(other *Pattern) bool {
5757 }
5858 var diffs int
5959 for i := range other .words {
60- if i > patternCheckFirstN {
61- return true
62- }
6360 if p .words [i ] != other .words [i ] {
6461 diffs ++
6562 if diffs > patternMaxDiff {
@@ -74,20 +71,28 @@ func NewPattern(input string) *Pattern {
7471 pattern := & Pattern {}
7572 for _ , p := range strings .Fields (removeQuotedAndBrackets (input )) {
7673 p = strings .TrimRight (p , "=:],;" )
77- if len (p ) < minWordLen {
74+ if len (p ) < patterMinWordLen {
7875 continue
7976 }
8077 if hex .MatchString (p ) || uuid .MatchString (p ) {
8178 continue
8279 }
8380 p = removeDigits (p )
84- if isWord (p ) {
85- pattern .words = append (pattern .words , p )
81+ if ! isWord (p ) {
82+ continue
83+ }
84+ pattern .words = append (pattern .words , p )
85+ if len (pattern .words ) >= patternMaxWords {
86+ break
8687 }
8788 }
8889 return pattern
8990}
9091
92+ func NewPatternFromWords (input string ) * Pattern {
93+ return & Pattern {words : strings .Split (input , " " )}
94+ }
95+
9196// like regexp match to `^[a-zA-Z][a-zA-Z._-]*[a-zA-Z]$`, but much faster
9297func isWord (s string ) bool {
9398 l := len (s ) - 1
You can’t perform that action at this time.
0 commit comments