Bug 1355630 - Use a set for membership testing; r?chmanchester
With ~42,000 entries in relpaths, this change drops execution time
of this loop from ~23s to ~0.01s.
MozReview-Commit-ID: Afm245tjWUQ
--- a/python/mozbuild/mozbuild/frontend/mach_commands.py
+++ b/python/mozbuild/mozbuild/frontend/mach_commands.py
@@ -266,24 +266,29 @@ class MozbuildFileCommands(MachCommandBa
finder = FileFinder(self.topsrcdir)
if repo:
reader_finder = MercurialRevisionFinder(repo, rev=rev,
recognize_repo_paths=True)
else:
reader_finder = default_finder
# Expand wildcards.
+ # One variable is for ordering. The other for membership tests.
+ # (Membership testing on a list can be slow.)
allpaths = []
+ all_paths_set = set()
for p in relpaths:
if '*' not in p:
- if p not in allpaths:
+ if p not in all_paths_set:
+ all_paths_set.add(p)
allpaths.append(p)
continue
if repo:
raise InvalidPathException('cannot use wildcard in version control mode')
for path, f in finder.find(p):
- if path not in allpaths:
+ if path not in all_paths_set:
+ all_paths_set.add(path)
allpaths.append(path)
reader = self._get_reader(finder=reader_finder)
return reader.files_info(allpaths)