You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2007/05/25 16:19:52 UTC

svn commit: r541668 - /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java

Author: schor
Date: Fri May 25 07:19:51 2007
New Revision: 541668

URL: http://svn.apache.org/viewvc?view=rev&rev=541668
Log:
No Jira - slight reorg of ensure_size for arrays of ints to package the code that does
expansion in another method.  This allows the most often used case to be inlined, and 
permits measurements of space tied to expansion.  In testing, it seems that after 100K
annotations are made, the whole thing gets inlined in some cases...

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java?view=diff&rev=541668&r1=541667&r2=541668
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/internal/util/IntArrayUtils.java Fri May 25 07:19:51 2007
@@ -32,29 +32,33 @@
     return ensure_size(array, req, default_growth_factor, default_multiplication_limit);
   }
 
+  // done this way to allow more inlining
   public static final int[] ensure_size(int[] array, int req, int growth_factor,
           int multiplication_limit) {
     if (array.length < req) {
-      int new_array_size;
-      if (array.length > 0) {
-        new_array_size = array.length;
-      } else {
-        return new int[req];
-      }
-      while (new_array_size < req) {
-        if (new_array_size < multiplication_limit) {
-          new_array_size = new_array_size * growth_factor;
-        } else {
-          new_array_size = new_array_size + multiplication_limit;
-        }
-      }
-      int[] new_array = new int[new_array_size];
-      System.arraycopy(array, 0, new_array, 0, array.length);
-      array = new_array;
+      return expand_size(array, req, growth_factor, multiplication_limit);
     }
     return array;
   }
 
+  private static final int[] expand_size(int[] array, int req, int growth_factor,
+          int multiplication_limit) {
+    if (array.length == 0)
+      return new int[req];
+    int new_array_size = array.length;
+    
+    while (new_array_size < req) {
+      if (new_array_size < multiplication_limit) {
+        new_array_size = new_array_size * growth_factor;
+      } else {
+        new_array_size = new_array_size + multiplication_limit;
+      }
+    }
+    int[] new_array = new int[new_array_size];
+    System.arraycopy(array, 0, new_array, 0, array.length);
+    return new_array;
+  }
+  
   public static final boolean[] ensure_size(boolean[] array, int req, int growth_factor,
           int multiplication_limit) {
     if (array.length < req) {