Commit f7b8db13 authored by Stefan Behnel's avatar Stefan Behnel

reduce overhead a bit when many string constants have the same cname

parent 9203677c
......@@ -847,7 +847,7 @@ class GlobalState(object):
# In time, hopefully the literals etc. will be
# supplied directly instead.
#
# const_cnames_used set global index of unique constant identifiers
# const_cnames_used dict global counter for unique constant identifiers
#
# parts {string:CCodeWriter}
......@@ -903,7 +903,7 @@ class GlobalState(object):
self.module_node = module_node # because some utility code generation needs it
# (generating backwards-compatible Get/ReleaseBuffer
self.const_cnames_used = set()
self.const_cnames_used = {}
self.string_const_index = {}
self.pyunicode_ptr_const_index = {}
self.int_const_index = {}
......@@ -1108,12 +1108,11 @@ class GlobalState(object):
def new_const_cname(self, prefix='', value=''):
value = replace_identifier('_', value)[:32].strip('_')
used = self.const_cnames_used
counter = 1
name_suffix = value
while name_suffix in used:
counter += 1
counter = used[value] = used[value] + 1
name_suffix = '%s_%d' % (value, counter)
used.add(name_suffix)
used[name_suffix] = 1
return "%s%s%s" % (Naming.const_prefix, prefix, name_suffix)
def add_cached_builtin_decl(self, entry):
......
......@@ -149,7 +149,7 @@ __doc__ = ur"""
True
>>> same_cname
[b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
[b'abc\xf0_2', b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
>>> newlines
'Aaa\n'
......@@ -194,7 +194,7 @@ uresc = ur'\12\'\"\\'
bytes_uescape = b'\u1234\U12345678\u\u1\u12\uX'
str_uescape = '\u0063\U00012345\N{SNOWMAN}\x42'
same_cname = [b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
same_cname = [b'abc\xf0_2', b'abc\xf0', b'abc\xf1', b'abc\xf2', b'abc\xf3', b'abc_2', b'abc_3']
newlines = "Aaa\n"
......
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