diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-02-15 13:39:52 +0000 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-02-15 13:39:52 +0000 |
commit | 0921ccf40f167ed524a1a2ff7023949f2542e14f (patch) | |
tree | 28e5f87af5ec96d4007f597fc966d1c2a56da9fe | |
parent | 8b34e3568a753a8d5774b91f2b4701aea7f9baf9 (diff) | |
parent | 3bbb90e746b5d7ca6850a20c181b0e6d57f5f6ce (diff) | |
download | buildstream-0921ccf40f167ed524a1a2ff7023949f2542e14f.tar.gz |
Merge branch 'bschubert/set-as-set' into 'master'
Use sets when checking for existence of an element
See merge request BuildStream/buildstream!1154
-rw-r--r-- | buildstream/_loader/loader.py | 14 | ||||
-rw-r--r-- | buildstream/_profile.py | 10 | ||||
-rw-r--r-- | buildstream/plugins/sources/tar.py | 4 |
3 files changed, 12 insertions, 16 deletions
diff --git a/buildstream/_loader/loader.py b/buildstream/_loader/loader.py index 17d7c63fb..7ccb9a37c 100644 --- a/buildstream/_loader/loader.py +++ b/buildstream/_loader/loader.py @@ -284,17 +284,17 @@ class Loader(): def _check_circular_deps(self, element, check_elements=None, validated=None, sequence=None): if check_elements is None: - check_elements = {} + check_elements = set() if validated is None: - validated = {} + validated = set() if sequence is None: sequence = [] # Skip already validated branches - if validated.get(element) is not None: + if element in validated: return - if check_elements.get(element) is not None: + if element in check_elements: # Create `chain`, the loop of element dependencies from this # element back to itself, by trimming everything before this # element from the sequence under consideration. @@ -306,15 +306,15 @@ class Loader(): .format(element.full_name, " -> ".join(chain))) # Push / Check each dependency / Pop - check_elements[element] = True + check_elements.add(element) sequence.append(element.full_name) for dep in element.dependencies: dep.element._loader._check_circular_deps(dep.element, check_elements, validated, sequence) - del check_elements[element] + check_elements.remove(element) sequence.pop() # Eliminate duplicate paths - validated[element] = True + validated.add(element) # _sort_dependencies(): # diff --git a/buildstream/_profile.py b/buildstream/_profile.py index 82902b03b..f29e070c4 100644 --- a/buildstream/_profile.py +++ b/buildstream/_profile.py @@ -26,7 +26,7 @@ import datetime import time # Track what profile topics are active -active_topics = {} +active_topics = set() active_profiles = {} initialized = False @@ -144,14 +144,10 @@ def profile_init(): if setting: topics = setting.split(':') for topic in topics: - active_topics[topic] = True + active_topics.add(topic) initialized = True def profile_enabled(topic): profile_init() - if active_topics.get(topic): - return True - if active_topics.get(Topics.ALL): - return True - return False + return topic in active_topics or Topics.ALL in active_topics diff --git a/buildstream/plugins/sources/tar.py b/buildstream/plugins/sources/tar.py index d4e30d9ba..31dc17497 100644 --- a/buildstream/plugins/sources/tar.py +++ b/buildstream/plugins/sources/tar.py @@ -154,7 +154,7 @@ class TarSource(DownloadableFileSource): # directory paths for the archived files. def _list_tar_paths(self, tar): - visited = {} + visited = set() for member in tar.getmembers(): # Remove any possible leading './', offer more consistent behavior @@ -170,7 +170,7 @@ class TarSource(DownloadableFileSource): for i in range(len(components) - 1): dir_component = '/'.join([components[j] for j in range(i + 1)]) if dir_component not in visited: - visited[dir_component] = True + visited.add(dir_component) try: # Dont yield directory members which actually do # exist in the archive |