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:23:37 UTC
svn commit: r1525813 -
/lucene/dev/trunk/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java
Author: shaie
Date: Tue Sep 24 08:23:37 2013
New Revision: 1525813
URL: http://svn.apache.org/r1525813
Log:
LUCENE-5237: assert parameters validity as well as minor improvements
Modified:
lucene/dev/trunk/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java
Modified: lucene/dev/trunk/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java?rev=1525813&r1=1525812&r2=1525813&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java (original)
+++ lucene/dev/trunk/lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java Tue Sep 24 08:23:37 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;
}
}