Skip to content

Commit 2ba6771

Browse files
committed
Factor out constant answer in a singleton to save lots of memory on start up.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1154726 13f79535-47bb-0310-9956-ffa450edef68
1 parent 446dbef commit 2ba6771

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

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

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
public class Rule {
8282

8383
private static class AppendableCharSeqeuence implements CharSequence {
84-
84+
8585
private final CharSequence left;
8686
private final CharSequence right;
8787
private final int length;
@@ -213,6 +213,16 @@ public static interface RMatcher {
213213
boolean find();
214214
}
215215

216+
private static class TrueRMatcher implements RMatcher {
217+
218+
static TrueRMatcher INSTANCE = new TrueRMatcher();
219+
220+
public boolean find() {
221+
return true;
222+
}
223+
224+
}
225+
216226
/**
217227
* A minimal wrapper around the functionality of Pattern that we use, to allow for alternate implementations.
218228
*/
@@ -497,11 +507,7 @@ public boolean find() {
497507
// matches every string
498508
return new RPattern() {
499509
public RMatcher matcher(CharSequence input) {
500-
return new RMatcher() {
501-
public boolean find() {
502-
return true;
503-
}
504-
};
510+
return TrueRMatcher.INSTANCE;
505511
}
506512
};
507513
} else if (startsWith) {
@@ -695,7 +701,7 @@ public boolean patternAndContextMatches(CharSequence input, int i) {
695701
if (i < 0) {
696702
throw new IndexOutOfBoundsException("Can not match pattern at negative indexes");
697703
}
698-
704+
699705
int patternLength = this.pattern.length();
700706
int ipl = i + patternLength;
701707

0 commit comments

Comments
 (0)