logo       
Google Custom Search
    AddThis Social Bookmark Button

FYI: Micro-optimization for HashMap.rehash(): msg#00229

Subject: FYI: Micro-optimization for HashMap.rehash()
Hi,

The following is a little micro-optimization for HashMap.rehash().

2004-04-29  Mark Wielaard  <mark@xxxxxxxxx>
 
        Reported by f.haeglsperger@xxxxxx [patch #2485]
        * java/util/HashMap.java (rehash): Add entry at start of bucket.

Your hash function has to be pretty for this to be noticeable. But bad
hash functions are not that rare so I guess this will help at least
someone.

Cheers,

Mark
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.2140
diff -u -r1.2140 ChangeLog
--- ChangeLog   29 Apr 2004 21:21:10 -0000      1.2140
+++ ChangeLog   29 Apr 2004 22:46:45 -0000
@@ -1,5 +1,10 @@
 2004-04-29  Mark Wielaard  <mark@xxxxxxxxx>
 
+       Reported by f.haeglsperger@xxxxxx [patch #2485]
+       * java/util/HashMap.java (rehash): Add entry at start of bucket.
+
+2004-04-29  Mark Wielaard  <mark@xxxxxxxxx>
+
        * java/io/RandomAccessFile.java (setLength): Set position to new
        length when new length is smaller then current position.
 
Index: java/util/HashMap.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/HashMap.java,v
retrieving revision 1.27
diff -u -r1.27 HashMap.java
--- java/util/HashMap.java      22 Apr 2004 11:24:39 -0000      1.27
+++ java/util/HashMap.java      29 Apr 2004 22:46:45 -0000
@@ -743,18 +743,9 @@
           {
             int idx = hash(e.key);
             HashEntry dest = buckets[idx];
-
-            if (dest != null)
-              {
-                while (dest.next != null)
-                  dest = dest.next;
-                dest.next = e;
-              }
-            else
-              buckets[idx] = e;
-
             HashEntry next = e.next;
-            e.next = null;
+            e.next = buckets[idx];
+            buckets[idx] = e;
             e = next;
           }
       }

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Commit-classpath mailing list
Commit-classpath@xxxxxxx
http://mail.gnu.org/mailman/listinfo/commit-classpath

Try Searching:
servers, voip, java, networking, microsoft ...
<Prev in Thread] Current Thread [Next in Thread>