Author: ggregory
Date: Sun Aug  7 17:09:04 2011
New Revision: 1154726

URL: http://svn.apache.org/viewvc?rev=1154726&view=rev
Log:
Factor out constant answer in a singleton to save lots of memory on start up.

Modified:
    
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java?rev=1154726&r1=1154725&r2=1154726&view=diff
==============================================================================
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java
 Sun Aug  7 17:09:04 2011
@@ -81,7 +81,7 @@ import java.util.regex.Pattern;
 public class Rule {
 
     private static class AppendableCharSeqeuence implements CharSequence {
-        
+
         private final CharSequence left;
         private final CharSequence right;
         private final int length;
@@ -213,6 +213,16 @@ public class Rule {
         boolean find();
     }
 
+    private static class TrueRMatcher implements RMatcher {
+
+        static TrueRMatcher INSTANCE = new TrueRMatcher();
+
+        public boolean find() {
+            return true;
+        }
+
+    }
+
     /**
      * A minimal wrapper around the functionality of Pattern that we use, to 
allow for alternate implementations.
      */
@@ -497,11 +507,7 @@ public class Rule {
                 // matches every string
                 return new RPattern() {
                     public RMatcher matcher(CharSequence input) {
-                        return new RMatcher() {
-                            public boolean find() {
-                                return true;
-                            }
-                        };
+                        return TrueRMatcher.INSTANCE;
                     }
                 };
             } else if (startsWith) {
@@ -695,7 +701,7 @@ public class Rule {
         if (i < 0) {
             throw new IndexOutOfBoundsException("Can not match pattern at 
negative indexes");
         }
-        
+
         int patternLength = this.pattern.length();
         int ipl = i + patternLength;
 


Reply via email to