diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-10-31 04:18:41 +0100 |
|---|---|---|
| committer | Ulf Magnusson <foo@bar.com> | 2018-11-01 01:18:38 +0100 |
| commit | d30b55043c4c771cdabf42847cf718a93cf86ab8 (patch) | |
| tree | 942afac98171131bcc589766e1477c60496cfc95 | |
| parent | dbd07bb85db0448502ee51aa43ea6ca27b84ed45 (diff) | |
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.
| -rw-r--r-- | kconfiglib.py | 30 |
1 files changed, 21 insertions, 9 deletions
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 |
