Fielddata: IntArrayRef is initialized with small array and grows if needed

This commit is contained in:
Martijn van Groningen 2013-01-30 10:57:52 +01:00
parent 5df37eaf75
commit f7692aeef2
2 changed files with 12 additions and 12 deletions

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.fielddata.ordinals;
import org.apache.lucene.util.ArrayUtil;
import org.elasticsearch.common.RamUsage;
import org.elasticsearch.index.fielddata.util.IntArrayRef;
@ -29,13 +30,6 @@ import org.elasticsearch.index.fielddata.util.IntArrayRef;
*/
public class MultiFlatArrayOrdinals implements Ordinals {
private ThreadLocal<IntArrayRef> intArrayRefCache = new ThreadLocal<IntArrayRef>() {
@Override
protected IntArrayRef initialValue() {
return new IntArrayRef(new int[ordinals.length]);
}
};
// ordinals with value 0 indicates no value
private final int[][] ordinals;
private final int numDocs;
@ -90,7 +84,7 @@ public class MultiFlatArrayOrdinals implements Ordinals {
@Override
public Docs ordinals() {
return new Docs(this, ordinals, intArrayRefCache.get());
return new Docs(this, ordinals);
}
public static class Docs implements Ordinals.Docs {
@ -101,11 +95,11 @@ public class MultiFlatArrayOrdinals implements Ordinals {
private final IntArrayRef intsScratch;
public Docs(MultiFlatArrayOrdinals parent, int[][] ordinals, IntArrayRef intsScratch) {
public Docs(MultiFlatArrayOrdinals parent, int[][] ordinals) {
this.parent = parent;
this.ordinals = ordinals;
this.iter = new IterImpl(ordinals);
this.intsScratch = intsScratch;
this.intsScratch = new IntArrayRef(new int[16]);
}
@Override
@ -143,6 +137,9 @@ public class MultiFlatArrayOrdinals implements Ordinals {
if (i == 0) return IntArrayRef.EMPTY;
break;
}
if (i >= intsScratch.values.length) {
intsScratch.values = ArrayUtil.grow(intsScratch.values);
}
intsScratch.values[i] = ordinal;
}
intsScratch.end = i;

View File

@ -20,6 +20,7 @@
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;
@ -182,7 +183,7 @@ public class SparseMultiArrayOrdinals implements Ordinals {
this.lookup = lookup;
this.ordinals = ordinals;
this.iter = new IterImpl(lookup, ordinals);
this.intsScratch = new IntArrayRef(new int[parent.numOrds]);
this.intsScratch = new IntArrayRef(new int[16]);
}
@Override
@ -239,11 +240,13 @@ public class SparseMultiArrayOrdinals implements Ordinals {
// System.out.println("Ordinal index: " + ordsIndex);
int[] ords = ordinals[allOrdsIndex];
int i = 0;
int ord;
while ((ord = ords[ordsIndex++]) > 0) {
intsScratch.values[i++] = ord;
if (i >= intsScratch.values.length) {
intsScratch.values = ArrayUtil.grow(intsScratch.values);
}
}
intsScratch.values[i++] = -ord;
intsScratch.end = i;