You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by sa...@apache.org on 2011/09/14 12:37:54 UTC

svn commit: r1170520 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilValidate.java

Author: sascharodekamp
Date: Wed Sep 14 10:37:53 2011
New Revision: 1170520

URL: http://svn.apache.org/viewvc?rev=1170520&view=rev
Log:
Building a String using concatenation in a loop (https://issues.apache.org/jira/browse/OFBIZ-4416). A patch from Dimitri Unruh: In UtilValidate.java some methods building a String using concatenation in a loop. We can obtaine better performance by using a StringBuilder

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilValidate.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilValidate.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilValidate.java?rev=1170520&r1=1170519&r2=1170520&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilValidate.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilValidate.java Wed Sep 14 10:37:53 2011
@@ -264,31 +264,31 @@ public class UtilValidate {
     /** Removes all characters which appear in string bag from string s. */
     public static String stripCharsInBag(String s, String bag) {
         int i;
-        String returnString = "";
+        StringBuilder stringBuilder = new StringBuilder("");
 
         // Search through string's characters one by one.
         // If character is not in bag, append to returnString.
         for (i = 0; i < s.length(); i++) {
             char c = s.charAt(i);
 
-            if (bag.indexOf(c) == -1) returnString += c;
+            if (bag.indexOf(c) == -1) stringBuilder.append(c);
         }
-        return returnString;
+        return stringBuilder.toString();
     }
 
     /** Removes all characters which do NOT appear in string bag from string s. */
     public static String stripCharsNotInBag(String s, String bag) {
         int i;
-        String returnString = "";
+        StringBuilder stringBuilder = new StringBuilder("");
 
         // Search through string's characters one by one.
         // If character is in bag, append to returnString.
         for (i = 0; i < s.length(); i++) {
             char c = s.charAt(i);
 
-            if (bag.indexOf(c) != -1) returnString += c;
+            if (bag.indexOf(c) != -1) stringBuilder.append(c);
         }
-        return returnString;
+        return stringBuilder.toString();
     }
 
     /** Removes all whitespace characters from s.