From 626b6eafa321989fe4dfa9387e989e0059682595 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 17 Nov 2017 22:12:45 +0100 Subject: Check for type first when parsing properties Most common case. Make it cheap by storing the list of type tokens separately instead of building the tuple each time through. Shaves a few % off the runtime for property parsing. --- kconfiglib.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index a23a8c6..865953d 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1621,7 +1621,13 @@ class Kconfig(object): if t0 is None: continue - if t0 == _T_DEPENDS: + if t0 in _TYPE_TOKENS: + node.item.orig_type = _TOKEN_TO_TYPE[t0] + + if self._peek_token() is not None: + prompt = (self._next_token(), self._parse_cond()) + + elif t0 == _T_DEPENDS: if not self._check_token(_T_ON): self._parse_error('expected "on" after "depends"') @@ -1679,18 +1685,11 @@ class Kconfig(object): implies.append((self._next_token(), self._parse_cond())) - elif t0 in (_T_BOOL, _T_TRISTATE, _T_INT, _T_HEX, _T_STRING): - node.item.orig_type = _TOKEN_TO_TYPE[t0] - - if self._peek_token() is not None: - prompt = (self._next_token(), self._parse_cond()) - elif t0 == _T_DEFAULT: defaults.append((self._parse_expr(False), self._parse_cond())) elif t0 in (_T_DEF_BOOL, _T_DEF_TRISTATE): node.item.orig_type = _TOKEN_TO_TYPE[t0] - defaults.append((self._parse_expr(False), self._parse_cond())) elif t0 == _T_PROMPT: @@ -4119,6 +4118,16 @@ _STRING_LEX = frozenset(( _T_TRISTATE, )) +# Tokens for types, excluding def_bool, def_tristate, etc., for quick +# checks during parsing +_TYPE_TOKENS = frozenset(( + _T_BOOL, + _T_TRISTATE, + _T_INT, + _T_HEX, + _T_STRING, +)) + # Note: This hack is no longer needed as of upstream commit c226456 # (kconfig: warn of unhandled characters in Kconfig commands). It # is kept around for backwards compatibility. -- cgit v1.2.3