LUCENE-2792: Revert generic ArrayUtil.grow(T[]) for now and add unchecked code back into FST package

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1045319 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2010-12-13 19:17:21 +00:00
parent 1cfb936649
commit fbab97a0f1
4 changed files with 37 additions and 9 deletions

View File

@ -19,7 +19,6 @@ package org.apache.lucene.util;
import java.util.Collection;
import java.util.Comparator;
import java.lang.reflect.Array;
/**
* Methods for manipulating arrays.
@ -430,6 +429,7 @@ public final class ArrayUtil {
return false;
}
/* DISABLE THIS FOR NOW: This has performance problems until Java creates intrinsics for Class#getComponentType() and Array.newInstance()
public static <T> T[] grow(T[] array, int minSize) {
if (array.length < minSize) {
@SuppressWarnings("unchecked") final T[] newArray =
@ -454,6 +454,7 @@ public final class ArrayUtil {
} else
return array;
}
*/
// Since Arrays.equals doesn't implement offsets for equals
/**

View File

@ -18,6 +18,7 @@ package org.apache.lucene.util.automaton.fst;
*/
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IntsRef;
@ -287,7 +288,9 @@ public class Builder<T> {
final int prefixLenPlus1 = pos1+1;
if (frontier.length < input.length+1) {
final UnCompiledNode<T>[] next = ArrayUtil.grow(frontier, input.length+1);
@SuppressWarnings("unchecked") final UnCompiledNode<T>[] next =
new UnCompiledNode[ArrayUtil.oversize(input.length+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(frontier, 0, next, 0, frontier.length);
for(int idx=frontier.length;idx<next.length;idx++) {
next[idx] = new UnCompiledNode<T>(this);
}
@ -450,7 +453,9 @@ public class Builder<T> {
assert label >= 0;
assert numArcs == 0 || label > arcs[numArcs-1].label: "arc[-1].label=" + arcs[numArcs-1].label + " new label=" + label + " numArcs=" + numArcs;
if (numArcs == arcs.length) {
final Arc<T>[] newArcs = ArrayUtil.grow(arcs);
@SuppressWarnings("unchecked") final Arc<T>[] newArcs =
new Arc[ArrayUtil.oversize(numArcs+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(arcs, 0, newArcs, 0, arcs.length);
for(int arcIdx=numArcs;arcIdx<newArcs.length;arcIdx++) {
newArcs[arcIdx] = new Arc<T>();
}

View File

@ -19,6 +19,7 @@ package org.apache.lucene.util.automaton.fst;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.RamUsageEstimator;
import java.io.IOException;
@ -30,7 +31,7 @@ public class BytesRefFSTEnum<T> {
private final FST<T> fst;
private BytesRef current = new BytesRef(10);
@SuppressWarnings("unchecked") private FST.Arc<T>[] arcs = (FST.Arc<T>[]) new FST.Arc[10];
@SuppressWarnings("unchecked") private FST.Arc<T>[] arcs = new FST.Arc[10];
// outputs are cumulative
@SuppressWarnings("unchecked") private T[] output = (T[]) new Object[10];
@ -235,8 +236,18 @@ public class BytesRefFSTEnum<T> {
private void grow() {
final int l = current.length + 1;
current.grow(l);
arcs = ArrayUtil.grow(arcs, l);
output = ArrayUtil.grow(output, l);
if (arcs.length < l) {
@SuppressWarnings("unchecked") final FST.Arc<T>[] newArcs =
new FST.Arc[ArrayUtil.oversize(l, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(arcs, 0, newArcs, 0, arcs.length);
arcs = newArcs;
}
if (output.length < l) {
@SuppressWarnings("unchecked") final T[] newOutput =
(T[]) new Object[ArrayUtil.oversize(l, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(output, 0, newOutput, 0, output.length);
output = newOutput;
}
}
private void appendOutput(T addedOutput) {

View File

@ -19,6 +19,7 @@ package org.apache.lucene.util.automaton.fst;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.IntsRef;
import org.apache.lucene.util.RamUsageEstimator;
import java.io.IOException;
@ -30,7 +31,7 @@ public class IntsRefFSTEnum<T> {
private final FST<T> fst;
private IntsRef current = new IntsRef(10);
@SuppressWarnings("unchecked") private FST.Arc<T>[] arcs = (FST.Arc<T>[]) new FST.Arc[10];
@SuppressWarnings("unchecked") private FST.Arc<T>[] arcs = new FST.Arc[10];
// outputs are cumulative
@SuppressWarnings("unchecked") private T[] output = (T[]) new Object[10];
@ -235,8 +236,18 @@ public class IntsRefFSTEnum<T> {
private void grow() {
final int l = current.length + 1;
current.grow(l);
arcs = ArrayUtil.grow(arcs, l);
output = ArrayUtil.grow(output, l);
if (arcs.length < l) {
@SuppressWarnings("unchecked") final FST.Arc<T>[] newArcs =
new FST.Arc[ArrayUtil.oversize(l, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(arcs, 0, newArcs, 0, arcs.length);
arcs = newArcs;
}
if (output.length < l) {
@SuppressWarnings("unchecked") final T[] newOutput =
(T[]) new Object[ArrayUtil.oversize(l, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
System.arraycopy(output, 0, newOutput, 0, output.length);
output = newOutput;
}
}
private void appendOutput(T addedOutput) {