From db6cb68b74bc3a9f88f802a0f32613f95df7b854 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Tue, 21 Aug 2018 13:02:13 +0200 Subject: Refactor write_config() a bit Since the 'top_node' menu node itself is skipped, we can start from there and move the tree walk to the beginning of the loop. For an empty configuration (top_node.list set to None) the tree walk immediately discovers that there are no more nodes and returns. --- kconfiglib.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 5aaedcc..a01df27 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1090,26 +1090,11 @@ class Kconfig(object): for sym in self._defined_syms_set: sym._written = False - node = self.top_node.list - if not node: - # Empty configuration - return - + # The 'top_node' menu node itself doesn't generate any output, so + # it's skipped over below + node = self.top_node while 1: - item = node.item - if isinstance(item, Symbol): - if not item._written: - item._written = True - f.write(item.config_string) - - elif expr_value(node.dep) and \ - ((item == MENU and expr_value(node.visibility)) or - item == COMMENT): - - f.write("\n#\n# {}\n#\n".format(node.prompt[0])) - - # Iterative tree walk using parent pointers - + # Jump to the next node with an iterative tree walk if node.list: node = node.list elif node.next: @@ -1123,6 +1108,21 @@ class Kconfig(object): else: return + # Write node + + item = node.item + + if isinstance(item, Symbol): + if not item._written: + item._written = True + f.write(item.config_string) + + elif expr_value(node.dep) and \ + ((item == MENU and expr_value(node.visibility)) or + item == COMMENT): + + f.write("\n#\n# {}\n#\n".format(node.prompt[0])) + def write_min_config(self, filename, header="# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib)\n"): """ -- cgit v1.2.3