Optimization: call System.arraycopy instead of manual for loop copying

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@476110 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2006-11-17 11:18:11 +00:00
parent 2b1dd87818
commit 7e3c1bfb0d
2 changed files with 5 additions and 6 deletions

View File

@ -221,6 +221,9 @@ Optimizations
queries involving term positions, including phrase queries. queries involving term positions, including phrase queries.
(Michael Busch via Yonik Seeley) (Michael Busch via Yonik Seeley)
12. LUCENE-714: Replaced 2 cases of manual for-loop array copying
with calls to System.arraycopy instead, in DocumentWriter.java.
(Nicolas Lalevee via Mike McCandless)
Test Cases Test Cases
1. Added TestTermScorer.java (Grant Ingersoll) 1. Added TestTermScorer.java (Grant Ingersoll)

View File

@ -206,8 +206,7 @@ final class DocumentWriter {
if (ti.positions.length == freq) { // positions array is full if (ti.positions.length == freq) { // positions array is full
int[] newPositions = new int[freq * 2]; // double size int[] newPositions = new int[freq * 2]; // double size
int[] positions = ti.positions; int[] positions = ti.positions;
for (int i = 0; i < freq; i++) // copy old positions to new System.arraycopy(positions, 0, newPositions, 0, freq);
newPositions[i] = positions[i];
ti.positions = newPositions; ti.positions = newPositions;
} }
ti.positions[freq] = position; // add new position ti.positions[freq] = position; // add new position
@ -216,10 +215,7 @@ final class DocumentWriter {
if (ti.offsets.length == freq){ if (ti.offsets.length == freq){
TermVectorOffsetInfo [] newOffsets = new TermVectorOffsetInfo[freq*2]; TermVectorOffsetInfo [] newOffsets = new TermVectorOffsetInfo[freq*2];
TermVectorOffsetInfo [] offsets = ti.offsets; TermVectorOffsetInfo [] offsets = ti.offsets;
for (int i = 0; i < freq; i++) System.arraycopy(offsets, 0, newOffsets, 0, freq);
{
newOffsets[i] = offsets[i];
}
ti.offsets = newOffsets; ti.offsets = newOffsets;
} }
ti.offsets[freq] = offset; ti.offsets[freq] = offset;