From 39bc30fbc37cd6e4dc6dc6f747ae4e76bdb12094 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 18 May 2018 00:02:33 +0200 Subject: Refactor help text parsing loop This is less twisty, and generates slightly smaller bytecode. Probably doesn't help to special-case the first line. --- kconfiglib.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index f3624c4..9c2e614 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2288,20 +2288,17 @@ class Kconfig(object): self._saved_line = line # "Unget" the line return - help_lines = [_dedent_rstrip(line, indent)] + # The help text goes on till the first non-empty line with less indent + # than the first line + + help_lines = [] # Small optimization add_help_line = help_lines.append - # The help text goes on till the first non-empty line with less indent - - while 1: + while line and (line.isspace() or _indentation(line) >= indent): + add_help_line(_dedent_rstrip(line, indent)) line = readline() self._linenr += 1 - if not (line and (line.isspace() or \ - _indentation(line) >= indent)): - break - - add_help_line(_dedent_rstrip(line, indent)) node.help = "\n".join(help_lines).rstrip() + "\n" self._saved_line = line # "Unget" the line -- cgit v1.2.3