You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2010/07/02 15:41:13 UTC

svn commit: r959982 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java

Author: mreutegg
Date: Fri Jul  2 13:41:13 2010
New Revision: 959982

URL: http://svn.apache.org/viewvc?rev=959982&view=rev
Log:
JCR-2670: Optimize ReadOnlyIndexReader.read(int[] docs, int[] freqs)

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

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java?rev=959982&r1=959981&r2=959982&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java Fri Jul  2 13:41:13 2010
@@ -16,13 +16,13 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import org.apache.lucene.index.TermDocs;
+import java.io.IOException;
+import java.util.BitSet;
+
 import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
 import org.apache.lucene.index.TermPositions;
 
-import java.util.BitSet;
-import java.io.IOException;
-
 /**
  * Overwrites the methods that would modify the index and throws an
  * {@link UnsupportedOperationException} in each of those methods. A
@@ -240,10 +240,10 @@ class ReadOnlyIndexReader extends RefCou
         /**
          * @inheritDoc
          */
-        public boolean next() throws IOException {
-            boolean hasNext = super.next();
-            while (hasNext && deleted.get(super.doc())) {
-                hasNext = super.next();
+        public final boolean next() throws IOException {
+            boolean hasNext = in.next();
+            while (hasNext && deleted.get(in.doc())) {
+                hasNext = in.next();
             }
             return hasNext;
         }
@@ -251,20 +251,37 @@ class ReadOnlyIndexReader extends RefCou
         /**
          * @inheritDoc
          */
-        public int read(int[] docs, int[] freqs) throws IOException {
-            int count;
-            for (count = 0; count < docs.length && next(); count++) {
-                docs[count] = doc();
-                freqs[count] = freq();
+        public final int read(int[] docs, int[] freqs) throws IOException {
+            for (;;) {
+                int num = in.read(docs, freqs);
+                if (num == 0) {
+                    // no more docs
+                    return 0;
+                }
+                // need to check for deleted docs
+                int numDeleted = 0;
+                for (int i = 0; i < num; i++) {
+                    if (deleted.get(docs[i])) {
+                        numDeleted++;
+                        continue;
+                    }
+                    // check if we need to shift
+                    if (numDeleted > 0) {
+                        docs[i - numDeleted] = docs[i];
+                        freqs[i - numDeleted] = freqs[i];
+                    }
+                }
+                if (num != numDeleted) {
+                    return num - numDeleted;
+                }
             }
-            return count;
         }
 
         /**
          * @inheritDoc
          */
-        public boolean skipTo(int i) throws IOException {
-            boolean exists = super.skipTo(i);
+        public final boolean skipTo(int i) throws IOException {
+            boolean exists = in.skipTo(i);
             while (exists && deleted.get(doc())) {
                 exists = next();
             }