summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2009-08-24 18:10:03 -0400
committerRich Hickey <richhickey@gmail.com>2009-08-26 12:02:58 -0400
commitc4a15a238e772d51f6eb2d38861c95cb4740ca3f (patch)
tree9336c87606e4ba25c6f48b1c34322f7433234b36
parent2cf6eb9e746ab1c610460badf4f99f1ee19bf0b3 (diff)
prealloc leaf box for transient map, grow by 4
Signed-off-by: Rich Hickey <richhickey@gmail.com>
-rw-r--r--src/jvm/clojure/lang/PersistentHashMap.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/jvm/clojure/lang/PersistentHashMap.java b/src/jvm/clojure/lang/PersistentHashMap.java
index 3fbabca9..3137e9c6 100644
--- a/src/jvm/clojure/lang/PersistentHashMap.java
+++ b/src/jvm/clojure/lang/PersistentHashMap.java
@@ -13,7 +13,6 @@ package clojure.lang;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicReference;
/*
@@ -193,8 +192,9 @@ static final class TransientHashMap extends ATransientMap {
int count;
boolean hasNull;
Object nullValue;
-
-
+ final Box leafFlag = new Box(null);
+
+
TransientHashMap(PersistentHashMap m) {
this(new AtomicReference<Thread>(Thread.currentThread()), m.root, m.count, m.hasNull, m.nullValue);
}
@@ -217,12 +217,13 @@ static final class TransientHashMap extends ATransientMap {
}
return this;
}
- Box addedLeaf = new Box(null);
+// Box leafFlag = new Box(null);
+ leafFlag.val = null;
INode n = (root == null ? BitmapIndexedNode.EMPTY : root)
- .assoc(edit, 0, Util.hash(key), key, val, addedLeaf);
+ .assoc(edit, 0, Util.hash(key), key, val, leafFlag);
if (n != this.root)
this.root = n;
- if(addedLeaf.val != null) this.count++;
+ if(leafFlag.val != null) this.count++;
return this;
}
@@ -235,11 +236,12 @@ static final class TransientHashMap extends ATransientMap {
return this;
}
if (root == null) return this;
- Box removedLeaf = new Box(null);
- INode n = root.without(edit, 0, Util.hash(key), key, removedLeaf);
+// Box leafFlag = new Box(null);
+ leafFlag.val = null;
+ INode n = root.without(edit, 0, Util.hash(key), key, leafFlag);
if (n != root)
this.root = n;
- if(removedLeaf.val != null) this.count--;
+ if(leafFlag.val != null) this.count--;
return this;
}
@@ -654,7 +656,7 @@ final static class BitmapIndexedNode implements INode{
}
return new ArrayNode(edit, n + 1, nodes);
} else {
- Object[] newArray = new Object[2*(n+2)];
+ Object[] newArray = new Object[2*(n+4)];
System.arraycopy(array, 0, newArray, 0, 2*idx);
newArray[2*idx] = key;
addedLeaf.val = newArray[2*idx+1] = val;