harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r832464 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java
Date Tue, 03 Nov 2009 15:57:44 GMT
Author: tellison
Date: Tue Nov  3 15:57:44 2009
New Revision: 832464

URL: http://svn.apache.org/viewvc?rev=832464&view=rev
Log:
Have a guess at the URLEncoded length to avoid buffer growth.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java?rev=832464&r1=832463&r2=832464&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLEncoder.java Tue
Nov  3 15:57:44 2009
@@ -49,7 +49,8 @@
      */
     @Deprecated
     public static String encode(String s) {
-        StringBuilder buf = new StringBuilder();
+        // Guess a bit bigger for encoded form
+        StringBuilder buf = new StringBuilder(s.length() + 16);
         for (int i = 0; i < s.length(); i++) {
             char ch = s.charAt(i);
             if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <=
'Z')
@@ -95,7 +96,8 @@
         // check for UnsupportedEncodingException
         "".getBytes(enc); //$NON-NLS-1$
 
-        StringBuffer buf = new StringBuffer();
+        // Guess a bit bigger for encoded form
+        StringBuffer buf = new StringBuffer(s.length() + 16);
         int start = -1;
         for (int i = 0; i < s.length(); i++) {
             char ch = s.charAt(i);



Mime
View raw message