Commit b6d2b2fc authored by Stefan Behnel's avatar Stefan Behnel

avoid repeated substring replacing for PYIDENT() entries in utility code

parent cc786153
...@@ -384,14 +384,18 @@ class UtilityCode(UtilityCodeBase): ...@@ -384,14 +384,18 @@ class UtilityCode(UtilityCodeBase):
def inject_string_constants(self, impl, output): def inject_string_constants(self, impl, output):
"""Replace 'PYIDENT("xyz")' by a constant Python identifier cname. """Replace 'PYIDENT("xyz")' by a constant Python identifier cname.
""" """
pystrings = re.findall('(PYIDENT\("([^"]+)"\))', impl) replacements = {}
any_replacements = False def externalise(matchobj):
for ref, name in pystrings: name = matchobj.group(1)
py_const = output.get_interned_identifier( try:
StringEncoding.EncodedString(name)) cname = replacements[name]
any_replacements = True except KeyError:
impl = impl.replace(ref, py_const.cname) cname = replacements[name] = output.get_interned_identifier(
return any_replacements, impl StringEncoding.EncodedString(name)).cname
return cname
impl = re.sub('PYIDENT\("([^"]+)"\)', externalise, impl)
return bool(replacements), impl
def put_code(self, output): def put_code(self, output):
if self.requires: if self.requires:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment