Fielddata: Moved the growing logic to IntArrayRef

This commit is contained in:
Martijn van Groningen 2013-01-30 11:20:41 +01:00
parent f7692aeef2
commit e074e00f76
3 changed files with 8 additions and 8 deletions

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.fielddata.ordinals;
import org.apache.lucene.util.ArrayUtil;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -137,9 +136,7 @@ public class MultiFlatArrayOrdinals implements Ordinals {
if (i == 0) return IntArrayRef.EMPTY;
break;
}
if (i >= intsScratch.values.length) {
intsScratch.values = ArrayUtil.grow(intsScratch.values);
}
intsScratch.growIfNeeded(i);
intsScratch.values[i] = ordinal;
}
intsScratch.end = i;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.fielddata.ordinals;
import gnu.trove.list.array.TIntArrayList;
import org.apache.lucene.util.ArrayUtil;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -244,9 +243,7 @@ public class SparseMultiArrayOrdinals implements Ordinals {
int ord;
while ((ord = ords[ordsIndex++]) > 0) {
intsScratch.values[i++] = ord;
if (i >= intsScratch.values.length) {
intsScratch.values = ArrayUtil.grow(intsScratch.values);
}
intsScratch.growIfNeeded(i);
}
intsScratch.values[i++] = -ord;
intsScratch.end = i;

View File

@ -57,6 +57,12 @@ public class IntArrayRef extends AbstractList<Integer> implements RandomAccess {
}
}
public void growIfNeeded(int index) {
if (index >= values.length) {
values = ArrayUtil.grow(values);
}
}
@Override
public int size() {
return end - start;