StringBuilder instead of StringBuffer in java.util package
Paul Sandoz
paul.sandoz at oracle.com
Tue Apr 22 12:06:05 UTC 2014
Hi Otávio,
These look like good finds. I bet there are lots more of them.
IntelliJ reports 284 possible uses in src/share/classes (see the "'StringBuffer' may be 'StringBuilder'" migration aid), but i have not verified all those. Perhaps we should do this more systematically over all the Java source?
--
Do you want to become an openJDK contributor? I don't see you in the OpenJDK census.
If you become a contributor:
http://openjdk.java.net/contribute/
then i can directly accept patches from you and commit them with you as the author
Paul.
On Apr 22, 2014, at 1:28 AM, Otávio Gonçalves de Santana <otaviojava at java.net> wrote:
> diff -r 57c1da89ae1a src/share/classes/java/util/prefs/Base64.java
> --- a/src/share/classes/java/util/prefs/Base64.java Wed Apr 16 12:32:36
> 2014 -0700
> +++ b/src/share/classes/java/util/prefs/Base64.java Mon Apr 21 20:20:57
> 2014 -0300
> @@ -57,7 +57,7 @@
> int numFullGroups = aLen/3;
> int numBytesInPartialGroup = aLen - 3*numFullGroups;
> int resultLen = 4*((aLen + 2)/3);
> - StringBuffer result = new StringBuffer(resultLen);
> + StringBuilder result = new StringBuilder(resultLen);
> char[] intToAlpha = (alternate ? intToAltBase64 : intToBase64);
>
> // Translate all full groups from byte array elements to Base64
> @@ -259,3 +259,4 @@
> }
> }
> }
> +
>
>
> diff -r 57c1da89ae1a
> src/share/classes/java/util/regex/PatternSyntaxException.java
> --- a/src/share/classes/java/util/regex/PatternSyntaxException.java Wed Apr
> 16 12:32:36 2014 -0700
> +++ b/src/share/classes/java/util/regex/PatternSyntaxException.java Mon Apr
> 21 20:21:52 2014 -0300
> @@ -105,7 +105,7 @@
> * @return The full detail message
> */
> public String getMessage() {
> - StringBuffer sb = new StringBuffer();
> + StringBuilder sb = new StringBuilder();
> sb.append(desc);
> if (index >= 0) {
> sb.append(" near index ");
> @@ -122,3 +122,4 @@
> }
>
> }
> +
>
>
> diff -r 57c1da89ae1a src/share/classes/java/util/Properties.java
> --- a/src/share/classes/java/util/Properties.java Wed Apr 16 12:32:36 2014
> -0700
> +++ b/src/share/classes/java/util/Properties.java Mon Apr 21 20:22:44 2014
> -0300
> @@ -602,7 +602,7 @@
> if (bufLen < 0) {
> bufLen = Integer.MAX_VALUE;
> }
> - StringBuffer outBuffer = new StringBuffer(bufLen);
> + StringBuilder outBuffer = new StringBuilder(bufLen);
>
> for(int x=0; x<len; x++) {
> char aChar = theString.charAt(x);
> @@ -1209,3 +1209,4 @@
> }
> }
> }
> +
>
> --
> Atenciosamente.
>
> Otávio Gonçalves de Santana
>
> blog: http://otaviosantana.blogspot.com.br/
> twitter: http://twitter.com/otaviojava
> site: http://www.otaviojava.com.br
> (11) 98255-3513
More information about the core-libs-dev
mailing list