From d56c1e4b866e14aa92b5d48c9cce98776ff82592 Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Mon, 20 Apr 2009 14:39:10 +0000 Subject: [PATCH] speed up countChars() git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@10563 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- uk/ac/sanger/artemis/io/LineGroup.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/uk/ac/sanger/artemis/io/LineGroup.java b/uk/ac/sanger/artemis/io/LineGroup.java index bc4c1b657..da8ec3eed 100644 --- a/uk/ac/sanger/artemis/io/LineGroup.java +++ b/uk/ac/sanger/artemis/io/LineGroup.java @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/LineGroup.java,v 1.12 2009-03-04 16:50:02 tjc Exp $ + * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/LineGroup.java,v 1.13 2009-04-20 14:39:10 tjc Exp $ */ package uk.ac.sanger.artemis.io; @@ -37,7 +37,7 @@ import uk.ac.sanger.artemis.util.LinePushBackReader; * that start with FT. * * @author Kim Rutherford - * @version $Id: LineGroup.java,v 1.12 2009-03-04 16:50:02 tjc Exp $ + * @version $Id: LineGroup.java,v 1.13 2009-04-20 14:39:10 tjc Exp $ * */ @@ -400,13 +400,12 @@ abstract class LineGroup private static int countChars (final String s, final char c) { int count = 0; - - for (int i = 0 ; i < s.length () ; ++i) + int index = 0; + while((index = s.indexOf(c, index)) > -1) { - if (s.charAt (i) == c) - ++count; + count++; + index++; } - return count; } -- GitLab