You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/06/18 09:31:15 UTC
svn commit: r548241 -
/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
Author: pyang
Date: Mon Jun 18 00:31:14 2007
New Revision: 548241
URL: http://svn.apache.org/viewvc?view=rev&rev=548241
Log:
Apply patch for HARMONY-4035([luni]TreeMap.remove should set removed entry links to null to facilitate GC)
Modified:
harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java?view=diff&rev=548241&r1=548240&r2=548241
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/TreeMap.java Mon Jun 18 00:31:14 2007
@@ -906,16 +906,24 @@
Comparable<K> object = null;
if (comparator == null) {
object = toComparable(key);
+ Entry<K, V> x = root;
+ while (x != null) {
+ result = object.compareTo(x.key);
+ if (result == 0) {
+ return x;
+ }
+ x = result < 0 ? x.left : x.right;
+ }
+ } else {
+ Entry<K, V> x = root;
+ while (x != null) {
+ result = comparator.compare(key, x.key);
+ if (result == 0) {
+ return x;
+ }
+ x = result < 0 ? x.left : x.right;
+ }
}
- Entry<K, V> x = root;
- while (x != null) {
- result = object != null ? object.compareTo(x.key) : comparator
- .compare(key, x.key);
- if (result == 0) {
- return x;
- }
- x = result < 0 ? x.left : x.right;
- }
return null;
}
@@ -1264,28 +1272,39 @@
fixup(x);
}
}
+ y.left = y.right = y.parent = null;
size--;
}
private Entry<K, V> rbInsert(K object) {
int result = 0;
Entry<K, V> y = null;
- if (size != 0) {
- Comparable<K> key = null;
- if (comparator == null) {
- key = toComparable(object);
- }
- Entry<K, V> x = root;
- while (x != null) {
- y = x;
- result = key != null ? key.compareTo(x.key) : comparator
- .compare(object, x.key);
- if (result == 0) {
- return x;
- }
- x = result < 0 ? x.left : x.right;
- }
- }
+ if (size != 0) {
+ Comparable<K> key = null;
+ if (comparator == null) {
+ key = toComparable(object);
+ Entry<K, V> x = root;
+ while (x != null) {
+ y = x;
+ result = key.compareTo(x.key);
+ if (result == 0) {
+ return x;
+ }
+ x = result < 0 ? x.left : x.right;
+ }
+ } else {
+ Entry<K, V> x = root;
+ while (x != null) {
+ y = x;
+ result = comparator.compare(object, x.key);
+ if (result == 0) {
+ return x;
+ }
+ x = result < 0 ? x.left : x.right;
+ }
+ }
+
+ }
size++;
modCount++;