diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2015-06-04 05:54:02 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2015-06-04 06:13:00 +0200 |
| commit | 3c14ff8941dd1ce337630c27db08f52ca68e19f9 (patch) | |
| tree | c61ee37d1e8cc609a9ce8489bafa92398a2f77b1 /kconfiglib.py | |
| parent | 14d7ee5f91005a5bf7178f3a258910de04fb672d (diff) | |
Order _parse_block() cases by frequency.
Probably not a noticeable win here, but might as well. The new ordering
isn't any worse than the old one in other respects.
Also remove a pointless assert. The condition would trigger an obvious
error immediately when false anyway.
Diffstat (limited to 'kconfiglib.py')
| -rw-r--r-- | kconfiglib.py | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 34f2b36..c7a5026 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -951,7 +951,6 @@ class Config(object): # part of whatever we were parsing earlier? See comment in # Config.__init__(). if self.end_line is not None: - assert self.end_line_tokens is not None tokens = self.end_line_tokens tokens.go_to_start() @@ -979,9 +978,8 @@ class Config(object): t0 = tokens.get_next() - # Have we reached the end of the block? - if t0 == end_marker: - return block + # Cases are ordered roughly by frequency, which speeds things up a + # bit if t0 == T_CONFIG or t0 == T_MENUCONFIG: # The tokenizer will automatically allocate a new Symbol object @@ -1002,6 +1000,56 @@ class Config(object): self._parse_properties(line_feeder, sym, deps, visible_if_deps) + elif t0 == T_SOURCE: + kconfig_file = tokens.get_next() + exp_kconfig_file = self._expand_sym_refs(kconfig_file) + f = os.path.join(self.base_dir, exp_kconfig_file) + + if not os.path.exists(f): + raise IOError, ('{0}:{1}: sourced file "{2}" (expands to\n' + '"{3}") not found. Perhaps base_dir\n' + '(argument to Config.__init__(), currently\n' + '"{4}") is set to the wrong value.' + .format(filename, + linenr, + kconfig_file, + exp_kconfig_file, + self.base_dir)) + + # Add items to the same block + self._parse_file(f, parent, deps, visible_if_deps, block) + + elif t0 == end_marker: + # We have reached the end of the block + return block + + elif t0 == T_IF: + # If statements are treated as syntactic sugar for adding + # dependencies to enclosed items and do not have an explicit + # object representation. + + dep_expr = self._parse_expr(tokens, None, line, filename, linenr) + self._parse_block(line_feeder, + T_ENDIF, + parent, + _make_and(dep_expr, deps), + visible_if_deps, + block) # Add items to the same block + + elif t0 == T_COMMENT: + comment = Comment() + comment.config = self + comment.parent = parent + + comment.filename = filename + comment.linenr = linenr + + comment.text = tokens.get_next() + self._parse_properties(line_feeder, comment, deps, visible_if_deps) + + block.add_item(comment) + self.comments.append(comment) + elif t0 == T_MENU: menu = Menu() self.menus.append(menu) @@ -1023,19 +1071,6 @@ class Config(object): block.add_item(menu) - elif t0 == T_IF: - # If statements are treated as syntactic sugar for adding - # dependencies to enclosed items and do not have an explicit - # object representation. - - dep_expr = self._parse_expr(tokens, None, line, filename, linenr) - self._parse_block(line_feeder, - T_ENDIF, - parent, - _make_and(dep_expr, deps), - visible_if_deps, - block) # Add items to the same block - elif t0 == T_CHOICE: # We support named choices already_defined = False @@ -1086,39 +1121,6 @@ class Config(object): if not already_defined: block.add_item(choice) - elif t0 == T_COMMENT: - comment = Comment() - comment.config = self - comment.parent = parent - - comment.filename = filename - comment.linenr = linenr - - comment.text = tokens.get_next() - self._parse_properties(line_feeder, comment, deps, visible_if_deps) - - block.add_item(comment) - self.comments.append(comment) - - elif t0 == T_SOURCE: - kconfig_file = tokens.get_next() - exp_kconfig_file = self._expand_sym_refs(kconfig_file) - f = os.path.join(self.base_dir, exp_kconfig_file) - - if not os.path.exists(f): - raise IOError, ('{0}:{1}: sourced file "{2}" (expands to\n' - '"{3}") not found. Perhaps base_dir\n' - '(argument to Config.__init__(), currently\n' - '"{4}") is set to the wrong value.' - .format(filename, - linenr, - kconfig_file, - exp_kconfig_file, - self.base_dir)) - - # Add items to the same block - self._parse_file(f, parent, deps, visible_if_deps, block) - elif t0 == T_MAINMENU: text = tokens.get_next() |
