Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ Other

* GITHUB#15799: Exclude JNA Cleaner from thread leak detection by LuceneTestCase. (Alan Woodward)

* GITHUB#15826: Use ArrayUtil#copyOfSubArray to simplify manual array copy patterns. (Zhang Chao)

======================= Lucene 10.4.0 =======================

API Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ private static final class PendingTerm extends PendingEntry {

public PendingTerm(BytesRef term, BlockTermState state) {
super(true);
this.termBytes = new byte[term.length];
System.arraycopy(term.bytes, term.offset, termBytes, 0, term.length);
this.termBytes = ArrayUtil.copyOfSubArray(term.bytes, term.offset, term.offset + term.length);
this.state = state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ public void add(int value) {
}

public int[] get() {
final int[] arr = new int[upto];
System.arraycopy(ints, 0, arr, 0, upto);
final int[] arr = ArrayUtil.copyOfSubArray(ints, 0, upto);
upto = 0;
return arr;
}
Expand Down Expand Up @@ -444,10 +443,9 @@ public DirectField(
if (hasPayloads) {
BytesRef payload = docsAndPositionsEnum.getPayload();
if (payload != null) {
byte[] payloadBytes = new byte[payload.length];
System.arraycopy(
payload.bytes, payload.offset, payloadBytes, 0, payload.length);
payloads[upto][pos] = payloadBytes;
payloads[upto][pos] =
ArrayUtil.copyOfSubArray(
payload.bytes, payload.offset, payload.offset + payload.length);
}
}
posUpto++;
Expand Down Expand Up @@ -477,8 +475,7 @@ public DirectField(

// System.out.println(skipCount + " skips: " + field);

this.termBytes = new byte[termOffset];
System.arraycopy(termBytes, 0, this.termBytes, 0, termOffset);
this.termBytes = ArrayUtil.copyOfSubArray(termBytes, 0, termOffset);

// Pack skips:
this.skips = new int[skipCount];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ private static final class PendingTerm extends PendingEntry {

public PendingTerm(BytesRef term, BlockTermState state) {
super(true);
this.termBytes = new byte[term.length];
System.arraycopy(term.bytes, term.offset, termBytes, 0, term.length);
this.termBytes = ArrayUtil.copyOfSubArray(term.bytes, term.offset, term.offset + term.length);
this.state = state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import org.apache.lucene.document.RangeFieldQuery.QueryType;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;

/**
Expand Down Expand Up @@ -182,10 +183,8 @@ protected String toString(byte[] ranges, int dimension) {
* @return The string representation for the range at the provided dimension
*/
private static String toString(byte[] ranges, int dimension) {
byte[] min = new byte[BYTES];
System.arraycopy(ranges, 0, min, 0, BYTES);
byte[] max = new byte[BYTES];
System.arraycopy(ranges, BYTES, max, 0, BYTES);
byte[] min = ArrayUtil.copyOfSubArray(ranges, 0, BYTES);
byte[] max = ArrayUtil.copyOfSubArray(ranges, BYTES, BYTES + BYTES);
return "[" + InetAddressPoint.decode(min) + " : " + InetAddressPoint.decode(max) + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1290,9 +1290,9 @@ private void invertTokenStream(int docID, IndexableField field, boolean first)
try {
termsHashPerField.add(invertState.termAttribute.getBytesRef(), docID);
} catch (MaxBytesLengthExceededException e) {
byte[] prefix = new byte[30];
BytesRef bigTerm = invertState.termAttribute.getBytesRef();
System.arraycopy(bigTerm.bytes, bigTerm.offset, prefix, 0, 30);
byte[] prefix =
ArrayUtil.copyOfSubArray(bigTerm.bytes, bigTerm.offset, bigTerm.offset + 30);
String msg =
"Document contains at least one immense term in field=\""
+ fieldInfo.name
Expand Down Expand Up @@ -1363,8 +1363,9 @@ private void invertTerm(int docID, IndexableField field, boolean first) throws I
try {
termsHashPerField.add(binaryValue, docID);
} catch (MaxBytesLengthExceededException e) {
byte[] prefix = new byte[30];
System.arraycopy(binaryValue.bytes, binaryValue.offset, prefix, 0, 30);
byte[] prefix =
ArrayUtil.copyOfSubArray(
binaryValue.bytes, binaryValue.offset, binaryValue.offset + 30);
String msg =
"Document contains at least one immense term in field=\""
+ fieldInfo.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public TopDocs rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int top

if (topN < hits.length) {
ArrayUtil.select(hits, 0, hits.length, topN, ScoreDoc.COMPARATOR);
ScoreDoc[] subset = new ScoreDoc[topN];
System.arraycopy(hits, 0, subset, 0, topN);
hits = subset;
hits = ArrayUtil.copyOfSubArray(hits, 0, topN);
}
Arrays.sort(hits, ScoreDoc.COMPARATOR);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ public TopDocs rescore(IndexSearcher searcher, TopDocs firstPassTopDocs, int top

if (topN < hits.length) {
ArrayUtil.select(hits, 0, hits.length, topN, sortDocComparator);
ScoreDoc[] subset = new ScoreDoc[topN];
System.arraycopy(hits, 0, subset, 0, topN);
hits = subset;
hits = ArrayUtil.copyOfSubArray(hits, 0, topN);
}

Arrays.sort(hits, sortDocComparator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ assert sortableBytesToBigInt(result, offset, bigIntSize).equals(bigInt)
* @see #bigIntToSortableBytes(BigInteger, int, byte[], int)
*/
public static BigInteger sortableBytesToBigInt(byte[] encoded, int offset, int length) {
byte[] bigIntBytes = new byte[length];
System.arraycopy(encoded, offset, bigIntBytes, 0, length);
byte[] bigIntBytes = ArrayUtil.copyOfSubArray(encoded, offset, offset + length);
// Flip the sign bit back to the original
bigIntBytes[0] ^= 0x80;
return new BigInteger(bigIntBytes);
Expand Down
4 changes: 1 addition & 3 deletions lucene/core/src/java/org/apache/lucene/util/PagedBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ public Reader freeze(boolean trim) {
throw new IllegalStateException("cannot freeze when copy(BytesRef, BytesRef) was used");
}
if (trim && upto < blockSize) {
final byte[] newBlock = new byte[upto];
System.arraycopy(currentBlock, 0, newBlock, 0, upto);
currentBlock = newBlock;
currentBlock = ArrayUtil.copyOfSubArray(currentBlock, 0, upto);
}
if (currentBlock == null) {
currentBlock = EMPTY_BYTES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,7 @@ public static int[] topoSortStates(Automaton a) {

if (upto < states.length) {
// There were dead states
int[] newStates = new int[upto];
System.arraycopy(states, 0, newStates, 0, upto);
states = newStates;
states = ArrayUtil.copyOfSubArray(states, 0, upto);
}

// Reverse the order:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.lucene.util.hnsw;

import org.apache.lucene.util.ArrayUtil;

/**
* A bounded min heap that stores floats. The top element is the lowest value of the heap.
*
Expand Down Expand Up @@ -59,9 +61,7 @@ public boolean offer(float value) {
}

public float[] getHeap() {
float[] result = new float[size];
System.arraycopy(this.heap, 1, result, 0, size);
return result;
return ArrayUtil.copyOfSubArray(this.heap, 1, 1 + size);
}

/**
Expand Down
Loading