summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2017-11-17 22:12:45 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2017-11-17 22:49:06 +0100
commit626b6eafa321989fe4dfa9387e989e0059682595 (patch)
tree530103e0e959d8d7bbc674ed4dc560a6c8bb7f62 /kconfiglib.py
parent24714ad985058e670ef04acdef353c7748cf7714 (diff)
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.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py25
1 files changed, 17 insertions, 8 deletions
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.