From 2e0f51734a30441869280b1107471cae6e087981 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Sat, 25 Aug 2018 04:10:29 +0200 Subject: Clean up expr_str() a bit - Test in the order AND, OR, NOT, like in other places. This matches the frequency too. - Use 'not isinstance(expr, tuple)', which is a bit faster than isinstance(expr, (Symbol, Choice)). --- kconfiglib.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kconfiglib.py b/kconfiglib.py index 3d46630..3a25c73 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -5028,14 +5028,9 @@ def expr_str(expr, sc_expr_str_fn=standard_sc_expr_str): Note that quoted values are represented as constants symbols (Symbol.is_constant == True). """ - if isinstance(expr, (Symbol, Choice)): + if not isinstance(expr, tuple): return sc_expr_str_fn(expr) - if expr[0] == NOT: - if isinstance(expr[1], tuple): - return "!({})".format(expr_str(expr[1], sc_expr_str_fn)) - return "!" + sc_expr_str_fn(expr[1]) # Symbol - if expr[0] == AND: return "{} && {}".format(_parenthesize(expr[1], OR, sc_expr_str_fn), _parenthesize(expr[2], OR, sc_expr_str_fn)) @@ -5046,6 +5041,11 @@ def expr_str(expr, sc_expr_str_fn=standard_sc_expr_str): return "{} || {}".format(_parenthesize(expr[1], AND, sc_expr_str_fn), _parenthesize(expr[2], AND, sc_expr_str_fn)) + if expr[0] == NOT: + if isinstance(expr[1], tuple): + return "!({})".format(expr_str(expr[1], sc_expr_str_fn)) + return "!" + sc_expr_str_fn(expr[1]) # Symbol + # Relation # # Relation operands are always symbols (quoted strings are constant -- cgit v1.2.3