diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-09 12:47:14 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-13 09:20:34 +0530 |
commit | 7b3d00fee4bc76e9b6492321572db7ddd6d7f674 (patch) | |
tree | 85fb646e08a8ea9be1a6fde507bb721011047d7c /mesonbuild/build.py | |
parent | ec47db6c0c6511d249b6d57fd24ca288e00eb9a3 (diff) | |
download | meson-7b3d00fee4bc76e9b6492321572db7ddd6d7f674.zip meson-7b3d00fee4bc76e9b6492321572db7ddd6d7f674.tar.gz meson-7b3d00fee4bc76e9b6492321572db7ddd6d7f674.tar.bz2 |
Use dict for self.build.compilers instead of list
Everywhere we use this object, we end up iterating over it and comparing
compiler.get_language() with something. Using a dict is the obvious
choice and simplifies a lot of code.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 79759ee..50436d4 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -88,8 +88,8 @@ class Build: self.environment = environment self.projects = {} self.targets = {} - self.compilers = [] - self.cross_compilers = [] + self.compilers = {} + self.cross_compilers = {} self.global_args = {} self.projects_args = {} self.global_link_args = {} @@ -109,26 +109,19 @@ class Build: self.dep_manifest = {} self.cross_stdlibs = {} - def has_language(self, language): - for i in self.compilers: - if i.get_language() == language: - return True - return False - def add_compiler(self, compiler): if self.static_linker is None and compiler.needs_static_linker(): self.static_linker = self.environment.detect_static_linker(compiler) - if self.has_language(compiler.get_language()): - return - self.compilers.append(compiler) + lang = compiler.get_language() + if lang not in self.compilers: + self.compilers[lang] = compiler def add_cross_compiler(self, compiler): if len(self.cross_compilers) == 0: self.static_cross_linker = self.environment.detect_static_linker(compiler) - for i in self.cross_compilers: - if i.get_language() == compiler.get_language(): - return - self.cross_compilers.append(compiler) + lang = compiler.get_language() + if lang not in self.cross_compilers: + self.cross_compilers[lang] = compiler def get_project(self): return self.projects[''] |