Fielddata: IntArrayRef is initialized with small array and grows if needed
This commit is contained in:
parent
5df37eaf75
commit
f7692aeef2
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue