LUCENE-10403: Add ArrayUtil#grow(T[]) (#644)

This commit is contained in:
Greg Miller 2022-02-08 09:43:55 -08:00 committed by GitHub
parent ce93d45532
commit 8178ffda00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 2 deletions

View File

@ -142,6 +142,8 @@ New Features
* LUCENE-10385: Implement Weight#count on IndexSortSortedNumericDocValuesRangeQuery * LUCENE-10385: Implement Weight#count on IndexSortSortedNumericDocValuesRangeQuery
to speed up computing the number of hits when possible. (Luca Cavanna, Adrien Grand) to speed up computing the number of hits when possible. (Luca Cavanna, Adrien Grand)
* LUCENE-10403: Add ArrayUtil#grow(T[]). (Greg Miller)
Improvements Improvements
--------------------- ---------------------

View File

@ -192,7 +192,7 @@ public final class SynonymFilter extends TokenFilter {
public void add(char[] output, int offset, int len, int endOffset, int posLength) { public void add(char[] output, int offset, int len, int endOffset, int posLength) {
if (count == outputs.length) { if (count == outputs.length) {
outputs = ArrayUtil.grow(outputs, count + 1); outputs = ArrayUtil.grow(outputs);
} }
if (count == endOffsets.length) { if (count == endOffsets.length) {
final int[] next = new int[ArrayUtil.oversize(1 + count, Integer.BYTES)]; final int[] next = new int[ArrayUtil.oversize(1 + count, Integer.BYTES)];

View File

@ -223,6 +223,11 @@ public final class ArrayUtil {
return copy; return copy;
} }
/** Returns a larger array, generally over-allocating exponentially */
public static <T> T[] grow(T[] array) {
return grow(array, 1 + array.length);
}
/** /**
* Returns an array whose size is at least {@code minSize}, generally over-allocating * Returns an array whose size is at least {@code minSize}, generally over-allocating
* exponentially * exponentially

View File

@ -713,7 +713,7 @@ public class FSTCompiler<T> {
+ " numArcs=" + " numArcs="
+ numArcs; + numArcs;
if (numArcs == arcs.length) { if (numArcs == arcs.length) {
final Arc<T>[] newArcs = ArrayUtil.grow(arcs, numArcs + 1); final Arc<T>[] newArcs = ArrayUtil.grow(arcs);
for (int arcIdx = numArcs; arcIdx < newArcs.length; arcIdx++) { for (int arcIdx = numArcs; arcIdx < newArcs.length; arcIdx++) {
newArcs[arcIdx] = new Arc<>(); newArcs[arcIdx] = new Arc<>();
} }