Fix accidentally quadratic code in compiler.ir.Function._add_name.

This commit is contained in:
whitequark 2015-07-29 21:36:31 +03:00
parent 6d8d0ff3f5
commit d7f9af4bb5
1 changed files with 9 additions and 7 deletions

View File

@ -396,6 +396,7 @@ class Function:
def __init__(self, typ, name, arguments): def __init__(self, typ, name, arguments):
self.type, self.name = typ, name self.type, self.name = typ, name
self.names, self.arguments, self.basic_blocks = set(), [], [] self.names, self.arguments, self.basic_blocks = set(), [], []
self.next_name = 1
self.set_arguments(arguments) self.set_arguments(arguments)
self.is_internal = False self.is_internal = False
@ -403,13 +404,14 @@ class Function:
self.names.remove(name) self.names.remove(name)
def _add_name(self, base_name): def _add_name(self, base_name):
name, counter = base_name, 1 if base_name == "":
while name in self.names or name == "": name = "v.{}".format(self.next_name)
if base_name == "": self.next_name += 1
name = "v.{}".format(str(counter)) elif base_name in self.names:
else: name = "{}.{}".format(base_name, self.next_name)
name = "{}.{}".format(name, counter) self.next_name += 1
counter += 1 else:
name = base_name
self.names.add(name) self.names.add(name)
return name return name