From d30b55043c4c771cdabf42847cf718a93cf86ab8 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 31 Oct 2018 04:18:41 +0100 Subject: Refactor _remove_ifs() Can get away with a single variable by assigning node.list earlier, and save a tiny bit of work with a chained assignment. Also clarify what the tricky Python chained assignments correspond to, where it matters. --- kconfiglib.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index 116eca7..1e320a5 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2486,7 +2486,12 @@ class Kconfig(object): self._warn("the menuconfig symbol {} has no prompt" .format(_name_and_loc(sym))) - # Tricky Python semantics: This assigns prev.next before prev + # Equivalent to + # + # prev.next = node + # prev = node + # + # due to tricky Python semantics. The order matters. prev.next = prev = node elif t0 is None: @@ -5804,17 +5809,24 @@ def _remove_ifs(node): # doesn't bother to do this, but we expose the menu tree directly, and it # makes it nicer to work with. - first = node.list - while first and not first.item: - first = first.next + cur = node.list + while cur and not cur.item: + cur = cur.next + + node.list = cur - cur = first while cur: if cur.next and not cur.next.item: - cur.next = cur.next.next - cur = cur.next - - node.list = first + # Equivalent to + # + # tmp = cur.next.next + # cur.next = tmp + # cur = tmp + # + # due to tricky Python semantics. The order matters. + cur.next = cur = cur.next.next + else: + cur = cur.next def _finalize_choice(node): # Finalizes a choice, marking each symbol whose menu node has the choice as -- cgit v1.2.3