diff --git a/contrib/CHANGES.txt b/contrib/CHANGES.txt index d5b9cb970c1..685f2aedb4c 100644 --- a/contrib/CHANGES.txt +++ b/contrib/CHANGES.txt @@ -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 diff --git a/contrib/analyzers/common/src/java/org/tartarus/snowball/Among.java b/contrib/analyzers/common/src/java/org/tartarus/snowball/Among.java index f8291eb451f..93ed6c67678 100644 --- a/contrib/analyzers/common/src/java/org/tartarus/snowball/Among.java +++ b/contrib/analyzers/common/src/java/org/tartarus/snowball/Among.java @@ -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); } diff --git a/contrib/analyzers/common/src/java/org/tartarus/snowball/SnowballProgram.java b/contrib/analyzers/common/src/java/org/tartarus/snowball/SnowballProgram.java index 03180330c4b..0aaa1de67d4 100644 --- a/contrib/analyzers/common/src/java/org/tartarus/snowball/SnowballProgram.java +++ b/contrib/analyzers/common/src/java/org/tartarus/snowball/SnowballProgram.java @@ -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;