Skip to content

Commit ab7a850

Browse files
committed
Precompile and resuse x3 regular expression in
DaitchMokotoffSoundex.Rule
1 parent 1c0c3ac commit ab7a850

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
4848
<action type="fix" dev="ggregory" due-to="Gary Gregory">Remove -nouses directive from maven-bundle-plugin. OSGi package imports now state 'uses' definitions for package imports, this doesn't affect JPMS (from org.apache.commons:commons-parent:80).</action>
4949
<action type="fix" dev="ggregory" due-to="Gary Gregory">Refactor DigestUtils.updateDigest(MessageDigest, File) to use NIO.</action>
5050
<action type="fix" dev="ggregory" due-to="Gary Gregory" issue="CODEC-328" >Clarify Javadoc for org.apache.commons.codec.digest.UnixCrypt.crypt(byte[],String).</action>
51+
<action type="fix" dev="ggregory" due-to="Gary Gregory">Precompile and resuse x3 regular expression in DaitchMokotoffSoundex.Rule.</action>
5152
<!-- ADD -->
5253
<action type="add" dev="ggregory" due-to="Gary Gregory">Add HmacUtils.hmac(Path).</action>
5354
<action type="add" dev="ggregory" due-to="Gary Gregory">Add HmacUtils.hmacHex(Path).</action>

src/main/java/org/apache/commons/codec/language/DaitchMokotoffSoundex.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626
import java.util.Scanner;
2727
import java.util.Set;
28+
import java.util.regex.Pattern;
2829

2930
import org.apache.commons.codec.CharEncoding;
3031
import org.apache.commons.codec.EncoderException;
@@ -160,6 +161,7 @@ public String toString() {
160161
* Inner class for storing rules.
161162
*/
162163
private static final class Rule {
164+
private static final Pattern PIPE = Pattern.compile("\\|");
163165
private final String pattern;
164166
private final String[] replacementAtStart;
165167
private final String[] replacementBeforeVowel;
@@ -168,9 +170,9 @@ private static final class Rule {
168170
private Rule(final String pattern, final String replacementAtStart, final String replacementBeforeVowel,
169171
final String replacementDefault) {
170172
this.pattern = pattern;
171-
this.replacementAtStart = replacementAtStart.split("\\|");
172-
this.replacementBeforeVowel = replacementBeforeVowel.split("\\|");
173-
this.replacementDefault = replacementDefault.split("\\|");
173+
this.replacementAtStart = PIPE.split(replacementAtStart);
174+
this.replacementBeforeVowel = PIPE.split(replacementBeforeVowel);
175+
this.replacementDefault = PIPE.split(replacementDefault);
174176
}
175177

176178
private int getPatternLength() {

0 commit comments

Comments
 (0)