LUCENE-2288: remove more unnecessary snowball object creation

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@917161 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-02-28 10:41:28 +00:00
parent d333d94922
commit 0a1472386a
3 changed files with 11 additions and 5 deletions

View File

@ -121,6 +121,10 @@ Optimizations
take advantage of this for faster performance.
(Steven Rowe, Uwe Schindler, Robert Muir)
* LUCENE-2194, LUCENE-2201, LUCENE-2288: Snowball stemmers in contrib/analyzers
have been optimized to work on char[] and remove unnecessary object creation.
(Shai Erera, Robert Muir)
Test Cases
* LUCENE-2115: Cutover contrib tests to use Java5 generics. (Kay Kay

View File

@ -34,6 +34,7 @@ package org.tartarus.snowball;
import java.lang.reflect.Method;
public class Among {
private static final Class<?>[] EMPTY_PARAMS = new Class[0];
public Among (String s, int substring_i, int result,
String methodname, SnowballProgram methodobject) {
this.s_size = s.length();
@ -46,7 +47,7 @@ public class Among {
} else {
try {
this.method = methodobject.getClass().
getDeclaredMethod(methodname, new Class[0]);
getDeclaredMethod(methodname, EMPTY_PARAMS);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}

View File

@ -44,8 +44,11 @@ import org.apache.lucene.util.RamUsageEstimator;
* refactored StringBuffers to StringBuilder
* uses char[] as buffer instead of StringBuffer/StringBuilder
* eq_s,eq_s_b,insert,replace_s take CharSequence like eq_v and eq_v_b
* reflection calls (Lovins, etc) use EMPTY_ARGS/EMPTY_PARAMS
*/
public abstract class SnowballProgram {
private static final Object[] EMPTY_ARGS = new Object[0];
protected SnowballProgram()
{
current = new char[8];
@ -337,8 +340,7 @@ public abstract class SnowballProgram {
if (w.method == null) return w.result;
boolean res;
try {
Object resobj = w.method.invoke(w.methodobject,
new Object[0]);
Object resobj = w.method.invoke(w.methodobject, EMPTY_ARGS);
res = resobj.toString().equals("true");
} catch (InvocationTargetException e) {
res = false;
@ -406,8 +408,7 @@ public abstract class SnowballProgram {
boolean res;
try {
Object resobj = w.method.invoke(w.methodobject,
new Object[0]);
Object resobj = w.method.invoke(w.methodobject, EMPTY_ARGS);
res = resobj.toString().equals("true");
} catch (InvocationTargetException e) {
res = false;