You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2010/12/13 20:17:22 UTC

svn commit: r1045319 - in /lucene/dev/trunk/lucene/src/java/org/apache/lucene/util: ArrayUtil.java automaton/fst/Builder.java automaton/fst/BytesRefFSTEnum.java automaton/fst/IntsRefFSTEnum.java

Author: uschindler
Date: Mon Dec 13 19:17:21 2010
New Revision: 1045319

URL: http://svn.apache.org/viewvc?rev=1045319&view=rev
Log:
LUCENE-2792: Revert generic ArrayUtil.grow(T[]) for now and add unchecked code back into FST package

Modified:
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/ArrayUtil.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/Builder.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/BytesRefFSTEnum.java
    lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/IntsRefFSTEnum.java

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/ArrayUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/ArrayUtil.java?rev=1045319&r1=1045318&r2=1045319&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/ArrayUtil.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/ArrayUtil.java Mon Dec 13 19:17:21 2010
@@ -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
   /**

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/Builder.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/Builder.java?rev=1045319&r1=1045318&r2=1045319&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/Builder.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/Builder.java Mon Dec 13 19:17:21 2010
@@ -18,6 +18,7 @@ package org.apache.lucene.util.automaton
  */
 
 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>();
         }

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/BytesRefFSTEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/BytesRefFSTEnum.java?rev=1045319&r1=1045318&r2=1045319&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/BytesRefFSTEnum.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/BytesRefFSTEnum.java Mon Dec 13 19:17:21 2010
@@ -19,6 +19,7 @@ package org.apache.lucene.util.automaton
 
 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) {

Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/IntsRefFSTEnum.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/IntsRefFSTEnum.java?rev=1045319&r1=1045318&r2=1045319&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/IntsRefFSTEnum.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/automaton/fst/IntsRefFSTEnum.java Mon Dec 13 19:17:21 2010
@@ -19,6 +19,7 @@ package org.apache.lucene.util.automaton
 
 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) {