[kaffe] CVS kaffe (dalibor): Fixed iteration in HashMap and Hashtable to use hasNext()

Kaffe CVS cvs-commits at kaffe.org
Sun Oct 5 10:09:02 PDT 2003


PatchSet 4099 
Date: 2003/10/05 17:06:57
Author: dalibor
Branch: HEAD
Tag: (none) 
Log:
Fixed iteration in HashMap and Hashtable to use hasNext()

Removed micro-optimization in putAll and putAllInternal that used size() to precompute the number
of steps necessary to iterate over a collection. Use hasNext(), like Sun apparently does.

Members: 
	ChangeLog:1.1694->1.1695 
	libraries/javalib/java/util/HashMap.java:1.18->1.19 
	libraries/javalib/java/util/Hashtable.java:1.28->1.29 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1694 kaffe/ChangeLog:1.1695
--- kaffe/ChangeLog:1.1694	Sun Oct  5 16:04:47 2003
+++ kaffe/ChangeLog	Sun Oct  5 17:06:57 2003
@@ -1,3 +1,13 @@
+2003-10-05  Stuart Ballard <stuart.ballard at corp.fast.net>
+
+	* libraries/javalib/java/util/HashMap.java:
+	(putAll, putAllInternal) Iterate over collection using hasNext()
+	instead of using size().
+
+	* libraries/javalib/java/util/Hashtable.java
+	(putAll, putAllInternal) Iterate over collection using hasNext()
+	instead of using size().
+	
 2003-10-05  Kiyo Inaba <inaba at src.ricoh.co.jp>
 
 	* kaffe/kaffevm/stackTrace.c:
Index: kaffe/libraries/javalib/java/util/HashMap.java
diff -u kaffe/libraries/javalib/java/util/HashMap.java:1.18 kaffe/libraries/javalib/java/util/HashMap.java:1.19
--- kaffe/libraries/javalib/java/util/HashMap.java:1.18	Tue Aug 12 23:02:19 2003
+++ kaffe/libraries/javalib/java/util/HashMap.java	Sun Oct  5 17:06:58 2003
@@ -381,8 +381,7 @@
   public void putAll(Map m)
   {
     Iterator itr = m.entrySet().iterator();
-    int msize = m.size();
-    while (msize-- > 0)
+    while (itr.hasNext())
       {
         Map.Entry e = (Map.Entry) itr.next();
         // Optimize in case the Entry is one of our own.
@@ -709,10 +708,10 @@
   void putAllInternal(Map m)
   {
     Iterator itr = m.entrySet().iterator();
-    int msize = m.size();
-    size = msize;
-    while (msize-- > 0)
+    size = 0;
+    while (itr.hasNext())
       {
+        size++;
 	Map.Entry e = (Map.Entry) itr.next();
 	Object key = e.getKey();
 	int idx = hash(key);
Index: kaffe/libraries/javalib/java/util/Hashtable.java
diff -u kaffe/libraries/javalib/java/util/Hashtable.java:1.28 kaffe/libraries/javalib/java/util/Hashtable.java:1.29
--- kaffe/libraries/javalib/java/util/Hashtable.java:1.28	Tue Aug 12 23:02:19 2003
+++ kaffe/libraries/javalib/java/util/Hashtable.java	Sun Oct  5 17:06:58 2003
@@ -510,7 +510,7 @@
   {
     Iterator itr = m.entrySet().iterator();
 
-    for (int msize = m.size(); msize > 0; msize--)
+    while (itr.hasNext())
       {
         Map.Entry e = (Map.Entry) itr.next();
         // Optimize in case the Entry is one of our own.
@@ -859,11 +859,11 @@
   void putAllInternal(Map m)
   {
     Iterator itr = m.entrySet().iterator();
-    int msize = m.size();
-    this.size = msize;
+    size = 0;
 
-    for (; msize > 0; msize--)
+    while (itr.hasNext())
       {
+        size++;
 	Map.Entry e = (Map.Entry) itr.next();
 	Object key = e.getKey();
 	int idx = hash(key);




More information about the kaffe mailing list