diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2015-06-05 05:07:42 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2015-06-05 05:07:42 +0200 |
| commit | afdc2511c60a2a84404fbd4b36698127b45e5da2 (patch) | |
| tree | 9710f0526e13ac048352ce7df6c1a64cc7cdb52e | |
| parent | 121d4a95ed0cd6cf64d64b92eedfb163a531d672 (diff) | |
Use the 'get' method of 'keyword' directly.
Small tokenizer optimization, similar to the regex optimizations.
| -rw-r--r-- | kconfiglib.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 4679126..945f3ee 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -640,7 +640,7 @@ class Config(object): # The current index in the string being tokenized i = initial_token_match.end() - keyword = keywords.get(initial_token_match.group(1)) + keyword = get_keyword(initial_token_match.group(1)) if keyword is None: # We expect a keyword as the first token _tokenization_error(s, filename, linenr) @@ -669,7 +669,7 @@ class Config(object): i = id_keyword_match.end() # Keyword? - keyword = keywords.get(name) + keyword = get_keyword(name) if keyword is not None: append(keyword) # What would ordinarily be considered a name is treated as a @@ -2023,8 +2023,9 @@ def _make_and(e1, e2): T_SELECT, T_RANGE, T_OPTION, T_ALLNOCONFIG_Y, T_ENV, T_DEFCONFIG_LIST, T_MODULES, T_VISIBLE) = range(0, 39) -# Keyword to token map -keywords = { +# Keyword to token map. Note that the get() method is assigned directly as a +# small optimization. +get_keyword = { "mainmenu" : T_MAINMENU, "menu" : T_MENU, "endmenu" : T_ENDMENU, @@ -2057,7 +2058,7 @@ keywords = { "env" : T_ENV, "defconfig_list" : T_DEFCONFIG_LIST, "modules" : T_MODULES, - "visible" : T_VISIBLE } + "visible" : T_VISIBLE }.get # Strings to use for True and False bool_str = { False : "false", True : "true" } |
