svn commit: r1170521 - /ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1170521 - /ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java

sascharodekamp
Author: sascharodekamp
Date: Wed Sep 14 10:38:50 2011
New Revision: 1170521

URL: http://svn.apache.org/viewvc?rev=1170521&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/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java

Modified: ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java?rev=1170521&r1=1170520&r2=1170521&view=diff
==============================================================================
--- ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java (original)
+++ ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/UtilValidate.java Wed Sep 14 10:38:50 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.