Index: lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java =================================================================== --- lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java (revision 1525521) +++ lucene/analysis/common/src/java/org/apache/lucene/analysis/util/StemmerUtil.java (working copy) @@ -85,11 +85,14 @@ * @param pos Position of character to delete * @param len length of input buffer * @return length of input buffer after deletion + * + * @lucene.internal */ 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; } @@ -101,11 +104,14 @@ * @param len Length of input buffer * @param nChars number of characters to delete * @return length of input buffer after deletion + * + * @lucene.internal */ 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; } }