commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r279985 - in /jakarta/commons/proper/lang/trunk: project.xml src/java/org/apache/commons/lang/RandomStringUtils.java
Date Sat, 10 Sep 2005 10:07:46 GMT
Author: scolebourne
Date: Sat Sep 10 03:07:41 2005
New Revision: 279985

URL: http://svn.apache.org/viewcvs?rev=279985&view=rev
Log:
Optimize performance of RandomStringUtils
bug 35170, from Shaun Kalley

Modified:
    jakarta/commons/proper/lang/trunk/project.xml
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/RandomStringUtils.java

Modified: jakarta/commons/proper/lang/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/project.xml?rev=279985&r1=279984&r2=279985&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/project.xml (original)
+++ jakarta/commons/proper/lang/trunk/project.xml Sat Sep 10 03:07:41 2005
@@ -233,6 +233,9 @@
 			<name>Marc Johnson</name>
 		</contributor>
 		<contributor>
+			<name>Shaun Kalley</name>
+		</contributor>
+		<contributor>
 			<name>Tetsuya Kaneuchi</name>
 		</contributor>
 		<contributor>

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/RandomStringUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/RandomStringUtils.java?rev=279985&r1=279984&r2=279985&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/RandomStringUtils.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/RandomStringUtils.java
Sat Sep 10 03:07:41 2005
@@ -231,7 +231,7 @@
             }
         }
 
-        StringBuffer buffer = new StringBuffer();
+        char[] buffer = new char[count];
         int gap = end - start;
 
         while (count-- != 0) {
@@ -241,16 +241,15 @@
             } else {
                 ch = chars[random.nextInt(gap) + start];
             }
-            if ((letters && numbers && Character.isLetterOrDigit(ch))
-                || (letters && Character.isLetter(ch))
+            if ((letters && Character.isLetter(ch))
                 || (numbers && Character.isDigit(ch))
                 || (!letters && !numbers)) {
-                buffer.append(ch);
+                buffer[count] = ch;
             } else {
                 count++;
             }
         }
-        return buffer.toString();
+        return new String(buffer);
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message