You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2008/10/24 17:32:25 UTC

svn commit: r707656 - /incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java

Author: eae
Date: Fri Oct 24 08:32:25 2008
New Revision: 707656

URL: http://svn.apache.org/viewvc?rev=707656&view=rev
Log:
UIMA-1212

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java?rev=707656&r1=707655&r2=707656&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexRepositoryImpl.java Fri Oct 24 08:32:25 2008
@@ -743,7 +743,11 @@
   private IntSet fsDeletedFromIndex;
   
   private IntSet fsReindexed;
-  
+
+  // Monitor indexes used to optimize getIndexedFS and flush
+  private IntVector usedIndexes;
+  private boolean[] isUsed;
+
   private FSIndexRepositoryImpl() {
     super();
   }
@@ -814,6 +818,8 @@
     for (int i = 0; i < this.detectIllegalIndexUpdates.length; i++) {
       this.detectIllegalIndexUpdates[i] = Integer.MIN_VALUE;
     }
+    this.usedIndexes = new IntVector();
+    this.isUsed = new boolean[numTypes];
   }
 
   /**
@@ -825,9 +831,15 @@
     }
     int max;
     ArrayList v;
-    // The first element is null. This is not good...
-    for (int i = 1; i < this.indexArray.length; i++) {
-      v = this.indexArray[i];
+
+    //Do nothing really fast!
+    if (this.usedIndexes.size() == 0) {
+      return;
+    }
+
+    for (int i = 0; i < this.usedIndexes.size(); i++) {
+      this.isUsed[this.usedIndexes.get(i)] = false;
+      v = this.indexArray[this.usedIndexes.get(i)];
       max = v.size();
       for (int j = 0; j < max; j++) {
         ((IndexIteratorCachePair) v.get(j)).index.flush();
@@ -839,6 +851,7 @@
     this.fsDeletedFromIndex = new IntSet();
     this.fsReindexed = new IntSet();
     this.logProcessed = false;
+    this.usedIndexes.removeAllElements();
   }
 
   public void addFS(int fsRef) {
@@ -1238,13 +1251,9 @@
     // implementation.
     SortedIntSet set;
     int jMax, indStrat;
-    // Iterate over all types.
-    for (int i = 0; i < this.indexArray.length; i++) {
-      iv = this.indexArray[i];
-      if (iv == null) {
-        // The 0 position is the only one that should be null.
-        continue;
-      }
+    // Iterate over indexes with something in there
+    for (int i = 0; i < this.usedIndexes.size(); i++) {
+      iv = this.indexArray[this.usedIndexes.get(i)];
       // Iterate over the indexes for the type.
       jMax = iv.size();
       // Create a vector of IICPs. If there is at least one sorted or bag
@@ -1396,6 +1405,11 @@
     if (this.cas.getCurrentMark() != null) {
       	logIndexOperation(fsRef, true);
     }
+    if (!this.isUsed[typeCode]) {
+      //mark this index as used
+      this.isUsed[typeCode] = true;
+      this.usedIndexes.add(typeCode);
+    }
   }
 
   private static final String getAutoIndexNameForType(Type type) {