Merge "ObjectIdSubclassMap: Micro-optimize wrapping at end of table"

This commit is contained in:
Shawn O. Pearce 2011-03-13 19:28:01 -04:00 committed by Code Review
commit b4f2913556
1 changed files with 10 additions and 14 deletions

View File

@ -92,16 +92,15 @@ public void clear() {
* @return the instance mapped to toFind, or null if no mapping exists.
*/
public V get(final AnyObjectId toFind) {
int i = toFind.w1 & mask;
final int msk = mask;
int i = toFind.w1 & msk;
final V[] tbl = table;
final int end = tbl.length;
V obj;
while ((obj = tbl[i]) != null) {
if (AnyObjectId.equals(obj, toFind))
return obj;
if (++i == end)
i = 0;
i = (i + 1) & msk;
}
return null;
}
@ -157,16 +156,15 @@ public <Q extends V> void add(final Q newValue) {
* type of instance to store.
*/
public <Q extends V> V addIfAbsent(final Q newValue) {
int i = newValue.w1 & mask;
final int msk = mask;
int i = newValue.w1 & msk;
final V[] tbl = table;
final int end = tbl.length;
V obj;
while ((obj = tbl[i]) != null) {
if (AnyObjectId.equals(obj, newValue))
return obj;
if (++i == end)
i = 0;
i = (i + 1) & msk;
}
if (++size == grow) {
@ -218,13 +216,11 @@ public void remove() {
}
private void insert(final V newValue) {
int j = newValue.w1 & mask;
final int msk = mask;
int j = newValue.w1 & msk;
final V[] tbl = table;
final int end = tbl.length;
while (tbl[j] != null) {
if (++j == end)
j = 0;
}
while (tbl[j] != null)
j = (j + 1) & msk;
tbl[j] = newValue;
}