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 2017/07/17 21:42:41 UTC

svn commit: r1802215 - /uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java

Author: schor
Date: Mon Jul 17 21:42:40 2017
New Revision: 1802215

URL: http://svn.apache.org/viewvc?rev=1802215&view=rev
Log:
no Jira - minor optimization - speed up access to DocumentAnnotation

Modified:
    uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java

Modified: uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=1802215&r1=1802214&r2=1802215&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Mon Jul 17 21:42:40 2017
@@ -745,6 +745,13 @@ public class CASImpl extends AbstractCas
    */
   FeatureStructureImplC pearBaseFs = null;
   
+  /**
+   * Optimization - keep a documentAnnotationIterator handy for getting a ref to the doc annot
+   *   Initialized lazily, synchronized
+   *   One per cas view
+   */
+  private FSIterator<Annotation> docAnnotIter = null;
+  
 //  private StackTraceElement[] addbackSingleTrace = null;  // for debug use only, normally commented out  
 
   // CASImpl(TypeSystemImpl typeSystem) {
@@ -1514,6 +1521,7 @@ public class CASImpl extends AbstractCas
         // initialized.
         
         tcas.mySofaRef = null;  // was in v2: (1 == view) ? -1 : 0;
+        tcas.docAnnotIter = null;
       }
     }
     this.svd.clearTrackingMarks();
@@ -4008,28 +4016,37 @@ public class CASImpl extends AbstractCas
       // base CAS has no document
       return null;
     }
-    FSIterator<T> it = this.<T>getAnnotationIndex(getTypeSystemImpl().docType).iterator();
+    FSIterator<Annotation> it = getDocAnnotIter();
+    it.moveToFirst();  // revalidate in case index updated
     if (it.isValid()) {
-      return it.get();
+      Annotation r = it.get();
+      return (T) (inPearContext() 
+                  ? pearConvert(r)
+                  : r);
     }
     return null;
   }
-  
+
+  private FSIterator<Annotation> getDocAnnotIter() {
+    if (docAnnotIter != null) {
+      return docAnnotIter;
+    }
+    synchronized (this) {
+      if (docAnnotIter == null) {
+        docAnnotIter = this.<Annotation>getAnnotationIndex(getTypeSystemImpl().docType).iterator();
+      }
+      return docAnnotIter;
+    }
+  }
   /**
    * 
    * @return the fs addr of the document annotation found via the index, or 0 if not there
    */
   public int ll_getDocumentAnnotation() {
-    if (this == this.svd.baseCAS) {
-      // base CAS has no document
-      return 0;
-    }
-    
-    FSIterator<FeatureStructure> it = getIndexRepository().getIndex(CAS.STD_ANNOTATION_INDEX, getTypeSystemImpl().docType).iterator();
-    if (it.isValid()) {
-      return it.get()._id();
-    }
-    return 0;
+    AnnotationFS r = getDocumentAnnotationNoCreate();
+    return (r == null) 
+             ? 0
+             : r._id();
   }
   
   @Override