jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cki...@apache.org
Subject svn commit: r601562 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
Date Wed, 05 Dec 2007 22:50:54 GMT
Author: ckiehl
Date: Wed Dec  5 14:50:49 2007
New Revision: 601562

URL: http://svn.apache.org/viewvc?rev=601562&view=rev
Log:
JCR-1251: Avoid creating objects

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java?rev=601562&r1=601561&r2=601562&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/DescendantSelfAxisQuery.java
Wed Dec  5 14:50:49 2007
@@ -27,6 +27,7 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Iterator;
 import java.util.List;
@@ -337,20 +338,27 @@
             // check if doc is a descendant of one of the context nodes
             int parentDoc = hResolver.getParent(doc);
 
-            List ancestorDocs = new ArrayList();
-            ancestorDocs.add(new Integer(parentDoc));
+            int ancestorCount = 0;
+            int[] ancestorDocs = new int[2];
+            ancestorDocs[ancestorCount++] = parentDoc;
 
             // traverse
             while (parentDoc != -1 && !contextHits.get(parentDoc)) {
                 parentDoc = hResolver.getParent(parentDoc);
-                ancestorDocs.add(new Integer(parentDoc));
+                // resize array if needed
+                if (ancestorCount == ancestorDocs.length) {
+                    // double the size of the new array
+                    int[] copy = new int[ancestorDocs.length * 2];
+                    System.arraycopy(ancestorDocs, 0, copy, 0, ancestorDocs.length);
+                    ancestorDocs = copy;
+                }
+                ancestorDocs[ancestorCount++] = parentDoc;
             }
-
             if (parentDoc != -1) {
                 // since current parentDoc is a descendant of one of the context
                 // docs we can promote all ancestorDocs to the context hits
-                for (Iterator iter = ancestorDocs.iterator(); iter.hasNext();) {
-                    contextHits.set(((Integer) iter.next()).intValue());
+                for (int i = 0; i < ancestorCount; i++) {
+                    contextHits.set(ancestorDocs[i]);
                 }
                 return true;
             }



Mime
View raw message