lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r635193 - /lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
Date Sun, 09 Mar 2008 08:26:17 GMT
Author: mikemccand
Date: Sun Mar  9 00:26:16 2008
New Revision: 635193

URL: http://svn.apache.org/viewvc?rev=635193&view=rev
Log:
LUCENE-1211: small speedup to DocumentsWriter by optimizing the common case of sorting only
2 values

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java?rev=635193&r1=635192&r2=635193&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/DocumentsWriter.java Sun Mar  9 00:26:16
2008
@@ -1023,6 +1023,14 @@
     void quickSort(Posting[] postings, int lo, int hi) {
       if (lo >= hi)
         return;
+      else if (hi == 1+lo) {
+        if (comparePostings(postings[lo], postings[hi]) > 0) {
+          final Posting tmp = postings[lo];
+          postings[lo] = postings[hi];
+          postings[hi] = tmp;
+        }
+        return;
+      }
 
       int mid = (lo + hi) >>> 1;
 
@@ -1081,6 +1089,14 @@
     void quickSort(PostingVector[] postings, int lo, int hi) {
       if (lo >= hi)
         return;
+      else if (hi == 1+lo) {
+        if (comparePostings(postings[lo].p, postings[hi].p) > 0) {
+          final PostingVector tmp = postings[lo];
+          postings[lo] = postings[hi];
+          postings[hi] = tmp;
+        }
+        return;
+      }
 
       int mid = (lo + hi) >>> 1;
 
@@ -1134,6 +1150,14 @@
     void quickSort(FieldData[] array, int lo, int hi) {
       if (lo >= hi)
         return;
+      else if (hi == 1+lo) {
+        if (array[lo].compareTo(array[hi]) > 0) {
+          final FieldData tmp = array[lo];
+          array[lo] = array[hi];
+          array[hi] = tmp;
+        }
+        return;
+      }
 
       int mid = (lo + hi) >>> 1;
 
@@ -1321,6 +1345,8 @@
      *  returns -1 if p1 < p2; 1 if p1 > p2; else 0.
      */
     int comparePostings(Posting p1, Posting p2) {
+      if (p1 == p2)
+        return 0;
       final char[] text1 = charPool.buffers[p1.textStart >> CHAR_BLOCK_SHIFT];
       int pos1 = p1.textStart & CHAR_BLOCK_MASK;
       final char[] text2 = charPool.buffers[p2.textStart >> CHAR_BLOCK_SHIFT];



Mime
View raw message