Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 575CF7D0F for ; Sun, 7 Aug 2011 17:09:27 +0000 (UTC) Received: (qmail 36391 invoked by uid 500); 7 Aug 2011 17:09:27 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 36200 invoked by uid 500); 7 Aug 2011 17:09:26 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 36193 invoked by uid 99); 7 Aug 2011 17:09:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Aug 2011 17:09:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 07 Aug 2011 17:09:24 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 35B142388903 for ; Sun, 7 Aug 2011 17:09:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1154726 - /commons/proper/codec/trunk/src/java/org/apache/commons/codec/language/bm/Rule.java Date: Sun, 07 Aug 2011 17:09:05 -0000 To: commits@commons.apache.org From: ggregory@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110807170905.35B142388903@eris.apache.org> 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;