Sfoglia il codice sorgente

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>
tags/v0.12.1
Shawn O. Pearce 13 anni fa
parent
commit
da548dfd2b

+ 5
- 4
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java Vedi File

@@ -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);
}

Loading…
Annulla
Salva