mirror of
https://github.com/restic/restic.git
synced 2024-12-23 00:07:25 +00:00
Fix quadratic time complexity of Snapshot.HasPaths
This commit is contained in:
parent
f481ad64c8
commit
d0f1060df7
1 changed files with 5 additions and 10 deletions
|
@ -237,19 +237,14 @@ func (sn *Snapshot) HasTagList(l []TagList) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (sn *Snapshot) hasPath(path string) bool {
|
||||
for _, snPath := range sn.Paths {
|
||||
if path == snPath {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HasPaths returns true if the snapshot has all of the paths.
|
||||
func (sn *Snapshot) HasPaths(paths []string) bool {
|
||||
m := make(map[string]struct{}, len(sn.Paths))
|
||||
for _, snPath := range sn.Paths {
|
||||
m[snPath] = struct{}{}
|
||||
}
|
||||
for _, path := range paths {
|
||||
if !sn.hasPath(path) {
|
||||
if _, ok := m[path]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue