lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm...@apache.org
Subject svn commit: r884190 - /lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermRef.java
Date Wed, 25 Nov 2009 16:41:30 GMT
Author: rmuir
Date: Wed Nov 25 16:41:29 2009
New Revision: 884190

URL: http://svn.apache.org/viewvc?rev=884190&view=rev
Log:
LUCENE-2090: make TermRef final, support endsWith for fast suffix comparisons

Modified:
    lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermRef.java

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermRef.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermRef.java?rev=884190&r1=884189&r2=884190&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermRef.java (original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/TermRef.java Wed Nov 25
16:41:29 2009
@@ -23,7 +23,7 @@
 /** Represents the UTF8 bytes[] for a term's text.  This is
  *  used when reading with the flex API, to avoid having to
  *  materialize full char[]. */
-public class TermRef {
+public final class TermRef {
 
   public byte[] bytes;
   public int offset;
@@ -102,19 +102,30 @@
     return other;
   }
 
-  public boolean startsWith(TermRef other) {
-    // nocommit: is this correct? Yes this is correct.
-    if (length < other.length) {
+  public boolean startsWith(TermRef other, int pos) {
+    // nocommit: maybe this one shouldn't be public...
+    if (pos < 0 || length - pos < other.length) {
       return false;
     }
-    for(int i=0;i<other.length;i++) {
-      if (bytes[offset+i] != other.bytes[other.offset+i]) {
+    int i = offset + pos;
+    int j = other.offset;
+    final int k = other.offset + other.length;
+    
+    while (j < k)
+      if (bytes[i++] != other.bytes[j++])
         return false;
-      }
-    }
+    
     return true;
   }
+  
+  public boolean startsWith(TermRef other) {
+    return startsWith(other, 0);
+  }
 
+  public boolean endsWith(TermRef other) {
+    return startsWith(other, length - other.length);   
+  }
+  
   @Override
   public int hashCode() {
     final int prime = 31;



Mime
View raw message