You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2012/08/23 21:31:44 UTC
svn commit: r1376661 -
/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
Author: tn
Date: Thu Aug 23 19:31:43 2012
New Revision: 1376661
URL: http://svn.apache.org/viewvc?rev=1376661&view=rev
Log:
Speed improvement for phonetic engine by implementing the suggested fixme.
Modified:
commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
Modified: commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java?rev=1376661&r1=1376660&r2=1376661&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java (original)
+++ commons/proper/codec/trunk/src/main/java/org/apache/commons/codec/language/bm/Rule.java Thu Aug 23 19:31:43 2012
@@ -617,13 +617,13 @@ public class Rule {
return false;
}
- // fixme: this is a readability/speed trade-off - these 3 expressions should be inlined for speed to avoid
- // evaluating latter ones if earlier ones have already failed, but that would make the code a lot harder to
- // read
- boolean patternMatches = input.subSequence(i, ipl).equals(this.pattern);
- boolean rContextMatches = this.rContext.isMatch(input.subSequence(ipl, input.length()));
- boolean lContextMatches = this.lContext.isMatch(input.subSequence(0, i));
-
- return patternMatches && rContextMatches && lContextMatches;
+ // evaluate the pattern, left context and right context
+ // fail early if any of the evaluations is not successful
+ if (!input.subSequence(i, ipl).equals(this.pattern)) {
+ return false;
+ } else if (!this.rContext.isMatch(input.subSequence(ipl, input.length()))) {
+ return false;
+ }
+ return this.lContext.isMatch(input.subSequence(0, i));
}
}