summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Grand <christophe@cgrand.net>2009-08-10 18:44:45 +0200
committerRich Hickey <richhickey@gmail.com>2009-08-26 12:02:57 -0400
commit652d53e93309d5cd6e3c7c9c078b1defe2d10c29 (patch)
tree2e2073d788669503ae4ce1594ca4404facf0b327
parentd8ab4c4606b2f2229ee27a7942a0eccc967e3a9c (diff)
refined HashCollisionNode
Signed-off-by: Rich Hickey <richhickey@gmail.com>
-rw-r--r--src/jvm/clojure/lang/PersistentHashMap2.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/jvm/clojure/lang/PersistentHashMap2.java b/src/jvm/clojure/lang/PersistentHashMap2.java
index 3d38469a..19e98560 100644
--- a/src/jvm/clojure/lang/PersistentHashMap2.java
+++ b/src/jvm/clojure/lang/PersistentHashMap2.java
@@ -784,7 +784,7 @@ final static class HashCollisionNode implements INode{
}
public int findIndex(Object key){
- for(int i = 0; i < array.length; i+=2)
+ for(int i = 0; i < 2*count; i+=2)
{
if(Util.equals(key, array[i]))
return i;
@@ -828,6 +828,11 @@ final static class HashCollisionNode implements INode{
return this;
return editAndSet(edit, idx+1, val);
}
+ if (array.length > 2*count) {
+ HashCollisionNode editable = editAndSet(edit, 2*count, key, 2*count+1, val);
+ editable.count++;
+ return editable;
+ }
Object[] newArray = new Object[array.length + 2];
System.arraycopy(array, 0, newArray, 0, array.length);
newArray[array.length] = key;
@@ -843,7 +848,7 @@ final static class HashCollisionNode implements INode{
int idx = findIndex(key);
if(idx == -1)
return this;
- if(array.length == 2)
+ if(count == 1)
return null;
HashCollisionNode editable = ensureEditable(edit);
editable.array[idx] = editable.array[2*count-2];