2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 02:48:55 +00:00

filter: short circuit if no negative patterns

This commit is contained in:
Michael Eischer 2021-09-17 23:13:49 +02:00 committed by Alexander Neumann
parent 2ee07ded2b
commit cd190bee14

View File

@ -253,6 +253,12 @@ func list(patterns []Pattern, checkChildMatches bool, str string) (matched bool,
if err != nil {
return false, false, err
}
hasNegatedPattern := false
for _, pat := range patterns {
hasNegatedPattern = hasNegatedPattern || pat.isNegated
}
for _, pat := range patterns {
m, err := match(pat, strs)
if err != nil {
@ -275,6 +281,11 @@ func list(patterns []Pattern, checkChildMatches bool, str string) (matched bool,
} else {
matched = matched || m
childMayMatch = childMayMatch || c
if matched && childMayMatch && !hasNegatedPattern {
// without negative patterns the result cannot change any more
break
}
}
}