提交 7bece680 编写于 作者: L Lukáš Doktor

avocado.core.multiplexer: Optimization

Let's use comprehensions for generating pools and itertools to flatten
the list of variants. This improves the performance ~10%.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 334e1215
...@@ -47,10 +47,7 @@ class MuxTree(object): ...@@ -47,10 +47,7 @@ class MuxTree(object):
if node.is_leaf: if node.is_leaf:
self.pools.append(node) self.pools.append(node)
else: else:
pools = [] self.pools.append([MuxTree(child) for child in node.children])
for mux_child in node.children:
pools.append(MuxTree(mux_child))
self.pools.append(pools)
@staticmethod @staticmethod
def _iter_mux_leaves(node): def _iter_mux_leaves(node):
...@@ -75,19 +72,12 @@ class MuxTree(object): ...@@ -75,19 +72,12 @@ class MuxTree(object):
if isinstance(pool, list): if isinstance(pool, list):
pools.append(itertools.chain(*pool)) pools.append(itertools.chain(*pool))
else: else:
pools.append([pool]) pools.append(pool)
pools = itertools.product(*pools) pools = itertools.product(*pools)
while True: while True:
# TODO: Implement 2nd level filteres here # TODO: Implement 2nd level filteres here
# TODO: This part takes most of the time, optimize it # TODO: This part takes most of the time, optimize it
dirty = pools.next() yield list(itertools.chain(*pools.next()))
ret = []
for pool in dirty:
if isinstance(pool, list):
ret.extend(pool)
else:
ret.append(pool)
yield ret
def yaml2tree(input_yamls, filter_only=None, filter_out=None, def yaml2tree(input_yamls, filter_only=None, filter_out=None,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册