harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r447817 - /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
Date Tue, 19 Sep 2006 11:16:34 GMT
Author: tellison
Date: Tue Sep 19 04:16:33 2006
New Revision: 447817

URL: http://svn.apache.org/viewvc?view=rev&rev=447817
Log:
Apply patch HARMONY-1493 ([classlib][luni] java.util.HashMap:avoid expand backed element array
more than once)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java?view=diff&rev=447817&r1=447816&r2=447817
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/HashMap.java
Tue Sep 19 04:16:33 2006
@@ -549,16 +549,18 @@
     @Override
     public void putAll(Map<? extends K, ? extends V> map) {
         if (map.entrySet() != null) {
+            int capacity = elementCount + map.size();
+            if (capacity > threshold) {
+                rehash(capacity);
+            }
             super.putAll(map);
         }
     }
 
-    void rehash() {
-        int length = elementData.length << 1;
-        if (length == 0) {
-            length = 1;
-        }
-        Entry<K,V>[] newData = newElementArray(length);
+    void rehash(int capacity) {
+        int length = (capacity == 0 ? 1 : capacity << 1);
+
+        Entry<K, V>[] newData = newElementArray(length);
         for (int i = 0; i < elementData.length; i++) {
             Entry<K,V> entry = elementData[i];
             while (entry != null) {
@@ -573,6 +575,10 @@
         }
         elementData = newData;
         computeMaxSize();
+    }
+
+    void rehash() {
+        rehash(elementData.length);
     }
 
     /**



Mime
View raw message