Commit 343064e8 authored by Robert Bradshaw's avatar Robert Bradshaw

Simplify and memoize specialization__name.

parent 750ce9c4
...@@ -28,6 +28,7 @@ class BaseType(object): ...@@ -28,6 +28,7 @@ class BaseType(object):
# List of attribute names of any subtypes # List of attribute names of any subtypes
subtypes = [] subtypes = []
_empty_declaration = None _empty_declaration = None
_specialization_name = None
default_format_spec = None default_format_spec = None
def can_coerce_to_pyobject(self, env): def can_coerce_to_pyobject(self, env):
...@@ -48,15 +49,15 @@ class BaseType(object): ...@@ -48,15 +49,15 @@ class BaseType(object):
return self._empty_declaration return self._empty_declaration
def specialization_name(self): def specialization_name(self):
# This is not entirely robust. if self._specialization_name is None:
safe = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789' # This is not entirely robust.
all = [] common_subs = (self.empty_declaration_code()
for c in self.empty_declaration_code().replace("unsigned ", "unsigned_").replace("long long", "long_long").replace(" ", "__"): .replace("unsigned ", "unsigned_")
if c in safe: .replace("long long", "long_long")
all.append(c) .replace(" ", "__"))
else: self._specialization_name = re.sub(
all.append('_%x_' % ord(c)) '[^a-zA-Z0-9_]', lambda x: '_%x_' % ord(x.group(0)), common_subs)
return ''.join(all) return self._specialization_name
def base_declaration_code(self, base_code, entity_code): def base_declaration_code(self, base_code, entity_code):
if entity_code: if entity_code:
......
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