From fc59c2f9c0054e2279a36f33ccea2438abd8b1f2 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 6 Aug 2016 23:49:57 +0200 Subject: Micro-optimize parse_val_and_cond() Saves a source line as well as some bytecode. Tuple evaluation is guaranteed to be from left to right: https://docs.python.org/2/reference/expressions.html#evaluation-order --- kconfiglib.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index b279f57..23afdf5 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -804,11 +804,10 @@ class Config(object): """Parses ' if ' constructs, where the 'if' part is optional. Returns a tuple containing the parsed expressions, with None as the second element if the 'if' part is missing.""" - val = self._parse_expr(tokens, stmt, line, filename, linenr, False) - if tokens.check(T_IF): - return (val, self._parse_expr(tokens, stmt, line, filename, - linenr)) - return (val, None) + return (self._parse_expr(tokens, stmt, line, filename, linenr, + False), + self._parse_expr(tokens, stmt, line, filename, linenr) + if tokens.check(T_IF) else None) # In case the symbol is defined in multiple locations, we need to # remember what prompts, defaults, and selects are new for this -- cgit v1.2.3