heuristics regexp engine configurable #3, adapt IsVendor optimization & tests

Regex collation optimization for IsVendor now fails gracefully.
Tests that are affected by non-RE2 syntax are explicitly marked.
This commit is contained in:
Alex Bezzubov
2023-02-16 17:55:57 +01:00
parent 8df9e1ecf2
commit 8246efecce
4 changed files with 79 additions and 76 deletions

View File

@ -63,7 +63,21 @@ func IsDotFile(path string) bool {
// IsVendor returns whether or not path is a vendor path.
func IsVendor(path string) bool {
return data.FastVendorMatcher.MatchString(path)
// fast path: single collatated regex, if the engine supports its syntax
if data.FastVendorMatcher != nil {
return data.FastVendorMatcher.MatchString(path)
}
// slow path: skip individual rules with unsupported syntax
for _, matcher := range data.VendorMatchers {
if matcher == nil {
continue
}
if matcher.MatchString(path) {
return true
}
}
return false
}
// IsTest returns whether or not path is a test path.