You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/03/27 19:09:24 UTC

svn commit: r1669640 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java

Author: mikemccand
Date: Fri Mar 27 18:09:24 2015
New Revision: 1669640

URL: http://svn.apache.org/r1669640
Log:
fix silly minor performance bug in CompiledAutomaton/Terms.intersect implementations

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java?rev=1669640&r1=1669639&r2=1669640&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/CompiledAutomaton.java Fri Mar 27 18:09:24 2015
@@ -78,7 +78,8 @@ public class CompiledAutomaton {
   /**
    * Shared common suffix accepted by the automaton. Only valid
    * for {@link AUTOMATON_TYPE#NORMAL}, and only when the
-   * automaton accepts an infinite language.
+   * automaton accepts an infinite language.  This will be null
+   * if the common prefix is length 0.
    */
   public final BytesRef commonSuffixRef;
 
@@ -202,7 +203,12 @@ public class CompiledAutomaton {
       commonSuffixRef = null;
     } else {
       // NOTE: this is a very costly operation!  We should test if it's really warranted in practice...
-      commonSuffixRef = Operations.getCommonSuffixBytesRef(binary, maxDeterminizedStates);
+      BytesRef suffix = Operations.getCommonSuffixBytesRef(binary, maxDeterminizedStates);
+      if (suffix.length == 0) {
+        commonSuffixRef = null;
+      } else {
+        commonSuffixRef = suffix;
+      }
     }
 
     // This will determinize the binary automaton for us:

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java?rev=1669640&r1=1669639&r2=1669640&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java Fri Mar 27 18:09:24 2015
@@ -1063,7 +1063,7 @@ final public class Operations {
    * Returns the longest string that is a prefix of all accepted strings and
    * visits each state at most once.  The automaton must be deterministic.
    * 
-   * @return common prefix
+   * @return common prefix, which can be an empty (length 0) String (never null)
    */
   public static String getCommonPrefix(Automaton a) {
     if (a.isDeterministic() == false) {
@@ -1097,7 +1097,7 @@ final public class Operations {
    * Returns the longest BytesRef that is a prefix of all accepted strings and
    * visits each state at most once.  The automaton must be deterministic.
    * 
-   * @return common prefix
+   * @return common prefix, which can be an empty (length 0) BytesRef (never null)
    */
   public static BytesRef getCommonPrefixBytesRef(Automaton a) {
     BytesRefBuilder builder = new BytesRefBuilder();
@@ -1159,7 +1159,7 @@ final public class Operations {
    * @param maxDeterminizedStates maximum number of states determinizing the
    *  automaton can result in.  Set higher to allow more complex queries and
    *  lower to prevent memory exhaustion.
-   * @return common suffix
+   * @return common suffix, which can be an empty (length 0) BytesRef (never null)
    */
   public static BytesRef getCommonSuffixBytesRef(Automaton a, int maxDeterminizedStates) {
     // reverse the language of the automaton, then reverse its common prefix.