aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-03-09 14:32:43 -0800
committerShawn O. Pearce <spearce@spearce.org>2011-03-09 14:32:43 -0800
commitda548dfd2b8ef9842cbb0c7da7183f50d93018a4 (patch)
treee6cbffb6f0eabd2b727b85f281f8dbf68c83be3d /org.eclipse.jgit
parent47c2a3a98d8371a8d622c5ff6af273f23864bfe6 (diff)
downloadjgit-da548dfd2b8ef9842cbb0c7da7183f50d93018a4.tar.gz
jgit-da548dfd2b8ef9842cbb0c7da7183f50d93018a4.zip
ObjectIdSubclassMap: Grow before insertions
If the table needs to be grown, do it before the current insertion rather than after. This is a tiny micro-optimization that allows the compiler to reuse the result of "++size" to compare against previously pre-computed size at which the table should rehash itself. Change-Id: Ief6f81b91c10ed433d67e0182f558ca70d58a2b0 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java9
1 files changed, 5 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java
index 290b534454..6162c221a3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java
@@ -67,6 +67,8 @@ public class ObjectIdSubclassMap<V extends ObjectId> implements Iterable<V> {
private int size;
+ private int grow;
+
private int mask;
private V[] table;
@@ -127,10 +129,9 @@ public class ObjectIdSubclassMap<V extends ObjectId> implements Iterable<V> {
* type of instance to store.
*/
public <Q extends V> void add(final Q newValue) {
- if (table.length - 1 <= size * 2)
+ if (++size == grow)
grow();
insert(newValue);
- size++;
}
/**
@@ -164,13 +165,12 @@ public class ObjectIdSubclassMap<V extends ObjectId> implements Iterable<V> {
i = 0;
}
- if (table.length - 1 <= size * 2) {
+ if (++size == grow) {
grow();
insert(newValue);
} else {
table[i] = newValue;
}
- size++;
return newValue;
}
@@ -239,6 +239,7 @@ public class ObjectIdSubclassMap<V extends ObjectId> implements Iterable<V> {
}
private void initTable(int sz) {
+ grow = sz >> 1;
mask = sz - 1;
table = createArray(sz);
}