Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: pylib/gyp/input.py

Issue 235193002: gyp: use a set() in DeepDependencies for less O(n^2). (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: DeepDependency: Restore the ordering. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pylib/gyp/input.py
diff --git a/pylib/gyp/input.py b/pylib/gyp/input.py
index f694e57b9fe455197bcd5eb423c48b66a8f0376e..7bf9b4035e36cc97d1bcb4e52286cd31bca97fa7 100644
--- a/pylib/gyp/input.py
+++ b/pylib/gyp/input.py
@@ -1602,15 +1602,22 @@ class DependencyGraphNode(object):
def DeepDependencies(self, dependencies=None):
"""Returns a list of all of a target's dependencies, recursively."""
if dependencies == None:
- dependencies = []
+ # Using a list to get ordered output and a set to do fast "is it
+ # already added" checks.
+ dependencies = ([], set())
+
+ dependency_list, dependency_set = dependencies
for dependency in self.dependencies:
# Check for None, corresponding to the root node.
- if dependency.ref != None and dependency.ref not in dependencies:
- dependencies.append(dependency.ref)
+ if dependency.ref is None:
+ continue
+ if dependency.ref not in dependency_set:
+ dependency_list.append(dependency.ref)
+ dependency_set.add(dependency.ref)
dependency.DeepDependencies(dependencies)
- return dependencies
+ return dependency_list
def _LinkDependenciesInternal(self, targets, include_shared_libraries,
dependencies=None, initial=True):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698