Skip to content

Commit 0f2c16e

Browse files
committed
Speed improvement for phonetic engine by implementing the suggested fixme.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1376661 13f79535-47bb-0310-9956-ffa450edef68
1 parent bdfc28e commit 0f2c16e

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • src/main/java/org/apache/commons/codec/language/bm

src/main/java/org/apache/commons/codec/language/bm/Rule.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,13 @@ public boolean patternAndContextMatches(CharSequence input, int i) {
617617
return false;
618618
}
619619

620-
// fixme: this is a readability/speed trade-off - these 3 expressions should be inlined for speed to avoid
621-
// evaluating latter ones if earlier ones have already failed, but that would make the code a lot harder to
622-
// read
623-
boolean patternMatches = input.subSequence(i, ipl).equals(this.pattern);
624-
boolean rContextMatches = this.rContext.isMatch(input.subSequence(ipl, input.length()));
625-
boolean lContextMatches = this.lContext.isMatch(input.subSequence(0, i));
626-
627-
return patternMatches && rContextMatches && lContextMatches;
620+
// evaluate the pattern, left context and right context
621+
// fail early if any of the evaluations is not successful
622+
if (!input.subSequence(i, ipl).equals(this.pattern)) {
623+
return false;
624+
} else if (!this.rContext.isMatch(input.subSequence(ipl, input.length()))) {
625+
return false;
626+
}
627+
return this.lContext.isMatch(input.subSequence(0, i));
628628
}
629629
}

0 commit comments

Comments
 (0)