changeset 19469:eb2e1729433e

Fix NodeUnionFind bug: Make union ignore nodes that are already in the same set.
author Roland Schatz <roland.schatz@oracle.com>
date Wed, 18 Feb 2015 11:46:16 +0100
parents 6709f8086756
children d216de21bfe8
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeUnionFind.java
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeUnionFind.java	Tue Feb 17 21:44:55 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/NodeUnionFind.java	Wed Feb 18 11:46:16 2015 +0100
@@ -73,12 +73,14 @@
     private void union(int a, int b) {
         int aRoot = find(a);
         int bRoot = find(b);
-        if (rank[aRoot] < rank[bRoot]) {
-            parent[aRoot] = bRoot;
-        } else {
-            parent[bRoot] = aRoot;
-            if (rank[aRoot] == rank[bRoot]) {
-                rank[aRoot]++;
+        if (aRoot != bRoot) {
+            if (rank[aRoot] < rank[bRoot]) {
+                parent[aRoot] = bRoot;
+            } else {
+                parent[bRoot] = aRoot;
+                if (rank[aRoot] == rank[bRoot]) {
+                    rank[aRoot]++;
+                }
             }
         }
     }