You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/09/24 10:24:45 UTC

svn commit: r1525814 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/analysis/ lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java

Author: shaie
Date: Tue Sep 24 08:24:45 2013
New Revision: 1525814

URL: http://svn.apache.org/r1525814
Log:
LUCENE-5237: assert parameters validity as well as minor improvements

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/   (props changed)
    lucene/dev/branches/branch_4x/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java

Modified: lucene/dev/branches/branch_4x/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java?rev=1525814&r1=1525813&r2=1525814&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java (original)
+++ lucene/dev/branches/branch_4x/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java Tue Sep 24 08:24:45 2013
@@ -17,7 +17,11 @@ package org.apache.lucene.analysis.util;
  * limitations under the License.
  */
 
-/** Some commonly-used stemming functions */
+/**
+ * Some commonly-used stemming functions
+ * 
+ * @lucene.internal
+ */
 public class StemmerUtil {
   /** no instance */
   private StemmerUtil() {}
@@ -87,9 +91,10 @@ public class StemmerUtil {
    * @return length of input buffer after deletion
    */
   public static int delete(char s[], int pos, int len) {
-    if (pos < len) 
+    assert pos < len;
+    if (pos < len - 1) { // don't arraycopy if asked to delete last character
       System.arraycopy(s, pos + 1, s, pos, len - pos - 1);
-    
+    }
     return len - 1;
   }
   
@@ -103,9 +108,10 @@ public class StemmerUtil {
    * @return length of input buffer after deletion
    */
   public static int deleteN(char s[], int pos, int len, int nChars) {
-    // TODO: speed up, this is silly
-    for (int i = 0; i < nChars; i++)
-      len = delete(s, pos, len);
-    return len;
+    assert pos + nChars <= len;
+    if (pos + nChars < len) { // don't arraycopy if asked to delete the last characters
+      System.arraycopy(s, pos + nChars, s, pos, len - pos - nChars);
+    }
+    return len - nChars;
   }
 }