forked from M-Labs/artiq
1
0
Fork 0

compiler.types: TVar.find: improve path compression.

After this change, the compiler's complexity is nearly linear
even when very large arrays are used.
This commit is contained in:
whitequark 2015-11-27 18:08:46 +08:00
parent bf1a583fda
commit 6122fd70ca
1 changed files with 7 additions and 1 deletions

View File

@ -71,7 +71,13 @@ class TVar(Type):
root = root.parent
# path compression
self.parent = root
iter = self
while isinstance(iter, TVar):
if iter is iter.parent:
break
else:
iter, iter.parent = iter.parent, root
return root
def unify(self, other):