summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-11-24 02:03:36 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-11-24 02:28:14 +0100
commit74ce9d348dd743af805484ccdd8a722a26aff42d (patch)
treecb13bfc4a5309e1b7a5e88b695c47d709af9ddb6
parent5be286d53aab6c8bf99549ae2eaa6bef3e84a86f (diff)
Optimize fetching of initial token on line
Another possible optimization was missed in commit ab89ef6 ("Get rid of _next_token() and _peek_token()"): The index of the initial token on a line is known to be 0, so there's no need to check _tokens_i. Also reads a bit clearer.
-rw-r--r--kconfiglib.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 6a62ee6..901f33b 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1807,7 +1807,9 @@ class Kconfig(object):
# it's part of a different construct
if self._reuse_tokens:
self._reuse_tokens = False
- self._tokens_i = 0
+ # self._tokens_i is known to be 1 here, because _parse_properties()
+ # leaves it like that when it can't recognize a line (or parses
+ # a help text)
return True
# Note: readline() returns '' over and over at EOF, which we rely on
@@ -1823,7 +1825,9 @@ class Kconfig(object):
self._linenr += 1
self._tokens = self._tokenize(self._line)
- self._tokens_i = 0 # Token index
+ # Initialize to 1 instead of 0 to factor out code from _parse_block()
+ # and _parse_properties(). They immediately fetch self._tokens[0].
+ self._tokens_i = 1
return True
@@ -2473,8 +2477,7 @@ class Kconfig(object):
# empty). This allows chaining.
while self._next_line():
- t0 = self._tokens[self._tokens_i]
- self._tokens_i += 1
+ t0 = self._tokens[0]
if t0 is _T_CONFIG or t0 is _T_MENUCONFIG:
# The tokenizer allocates Symbol objects for us
@@ -2702,8 +2705,7 @@ class Kconfig(object):
node.dep = self.y
while self._next_line():
- t0 = self._tokens[self._tokens_i]
- self._tokens_i += 1
+ t0 = self._tokens[0]
if t0 in _TYPE_TOKENS:
self._set_type(node, _TOKEN_TO_TYPE[t0])