commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [lang] LANG-1206: Improve CharSetUtils.squeeze() performance (closes #147)
Date Sun, 29 May 2016 15:06:56 GMT
Repository: commons-lang
Updated Branches:
  refs/heads/master f26f04dc6 -> afedbae8a


LANG-1206: Improve CharSetUtils.squeeze() performance (closes #147)

patch by Mohammed Alfallaj


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/afedbae8
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/afedbae8
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/afedbae8

Branch: refs/heads/master
Commit: afedbae8aca69a092d65766640361801bf2b5d9b
Parents: f26f04d
Author: pascalschumacher <pascalschumacher@gmx.net>
Authored: Fri May 20 20:04:30 2016 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Sun May 29 17:05:23 2016 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../org/apache/commons/lang3/CharSetUtils.java  | 23 +++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/afedbae8/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index bd03520..a03b992 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,7 @@
   <body>
 
   <release version="3.5" date="tba" description="tba">
+    <action issue="LANG-1206" type="update" dev="pschumacher" due-to="Mohammed Alfallaj">Improve
CharSetUtils.squeeze() performance</action>
     <action issue="LANG-1225" type="add" dev="pschumacher" due-to="Caleb Cushing">Add
RandomStringUtils#randomGraph and #randomPrint which match corresponding regular expression
class</action>
     <action issue="LANG-901" type="fix" dev="pschumacher" due-to="Matthew Bartenschlag">StringUtils#startsWithAny/endsWithAny
is case sensitive - documented as case insensitive</action>
     <action issue="LANG-1223" type="add" dev="pschumacher" due-to="Nick Manley">Add
StopWatch#getTime(TimeUnit)</action>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/afedbae8/src/main/java/org/apache/commons/lang3/CharSetUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharSetUtils.java b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
index 8599674..67d6fea 100644
--- a/src/main/java/org/apache/commons/lang3/CharSetUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharSetUtils.java
@@ -68,13 +68,26 @@ public class CharSetUtils {
         final StringBuilder buffer = new StringBuilder(str.length());
         final char[] chrs = str.toCharArray();
         final int sz = chrs.length;
-        char lastChar = ' ';
+        char lastChar = chrs[0];
         char ch = ' ';
-        for (int i = 0; i < sz; i++) {
+        Character inChars = null;
+        Character notInChars = null;
+        buffer.append(lastChar);
+        for (int i = 1; i < sz; i++) {
             ch = chrs[i];
-            // Compare with contains() last for performance.
-            if (ch == lastChar && i != 0 && chars.contains(ch)) {
-                continue;
+            if (ch == lastChar) {
+                if ((inChars != null) && (ch == inChars)) {
+                    continue;
+                } else {
+                    if ((notInChars == null) || (ch != notInChars)) {
+                        if (chars.contains(ch)) {
+                            inChars = ch;
+                            continue;
+                        } else {
+                            notInChars = ch;
+                        }
+                    }
+                }
             }
             buffer.append(ch);
             lastChar = ch;


Mime
View raw message