From 48920b44f093a4bceb5f043ab15458e28953a9b7 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Sun, 10 Jul 2011 17:50:21 +0000 Subject: [PATCH] [LANG-715] CharSetUtils.squeeze() speedup. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1144916 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/lang3/CharSetUtils.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/CharSetUtils.java b/src/main/java/org/apache/commons/lang3/CharSetUtils.java index 973b75847..05bcce549 100644 --- a/src/main/java/org/apache/commons/lang3/CharSetUtils.java +++ b/src/main/java/org/apache/commons/lang3/CharSetUtils.java @@ -73,10 +73,9 @@ public class CharSetUtils { char ch = ' '; for (int i = 0; i < sz; i++) { ch = chrs[i]; - if (chars.contains(ch)) { - if ((ch == lastChar) && (i != 0)) { - continue; - } + // Compare with contains() last for performance. + if (ch == lastChar && i != 0 && chars.contains(ch)) { + continue; } buffer.append(ch); lastChar = ch;