forked from M-Labs/artiq
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:
parent
bf1a583fda
commit
6122fd70ca
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue