summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2017-09-25 15:11:46 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2017-09-25 15:31:48 +0200
commit431ae39a3743d6c59aaa4a495653bc72e7bfee6b (patch)
treec0c4a708e3b961bdbf86d6922b0e7ff54306b014 /kconfiglib.py
parent9b89ed90812655a25f4afae8937d3d664fddd7c7 (diff)
Only compile .config matching regexes once
We only look at the value $CONFIG_ had when the configuration was loaded, so it's safe. Forgotten cleanup.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index ca18226..2a3cfea 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -185,6 +185,12 @@ class Config(object):
if self._config_prefix is None:
self._config_prefix = "CONFIG_"
+ # Regular expressions for parsing .config files
+ self._set_re = re.compile(r"{}(\w+)=(.*)"
+ .format(self._config_prefix))
+ self._unset_re = re.compile(r"# {}(\w+) is not set"
+ .format(self._config_prefix))
+
self._filename = filename
# See Config.__init__(). We need this for get_defconfig_filename().
@@ -407,25 +413,23 @@ class Config(object):
replace (default: True): True if the configuration should replace the
old configuration; False if it should add to it."""
- # Regular expressions for parsing .config files
- _set_re_match = re.compile(r"{}(\w+)=(.*)"
- .format(self._config_prefix)).match
- _unset_re_match = re.compile(r"# {}(\w+) is not set"
- .format(self._config_prefix)).match
-
# Put this first so that a missing file doesn't screw up our state
filename = os.path.expandvars(filename)
line_feeder = _FileFeed(filename)
self._config_filename = filename
+ # Small optimization
+ set_re_match = self._set_re.match
+ unset_re_match = self._unset_re.match
+
#
# Read header
#
def is_header_line(line):
return line is not None and line.startswith("#") and \
- not _unset_re_match(line)
+ not unset_re_match(line)
self._config_header = None
@@ -466,7 +470,7 @@ class Config(object):
line = line.rstrip()
- set_match = _set_re_match(line)
+ set_match = set_re_match(line)
if set_match:
name, val = set_match.groups()
@@ -502,7 +506,7 @@ class Config(object):
.format(val, name),
line_feeder.filename, line_feeder.linenr)
else:
- unset_match = _unset_re_match(line)
+ unset_match = unset_re_match(line)
if unset_match:
name = unset_match.group(1)
if name in self._syms: