diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-08-21 13:02:13 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-08-21 14:26:37 +0200 |
| commit | db6cb68b74bc3a9f88f802a0f32613f95df7b854 (patch) | |
| tree | 4db5b8aee766066d34fcd54ee5db29da7ae41e7c | |
| parent | 6d3b5e7dfc1d564727f9009d3bec83d54eb090ee (diff) | |
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.
| -rw-r--r-- | kconfiglib.py | 38 |
1 files changed, 19 insertions, 19 deletions
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"): """ |
