Inefficient use StringBuffer or StringBuilder[Optimization|clean-up] {Package: con.sun. * java.lang*}
Andrew Haley
aph at redhat.com
Fri Jun 7 13:54:06 UTC 2013
On 06/07/2013 02:18 PM, Otávio Gonçalves de Santana wrote:
> Inefficient use StringBuffer or StringBuilder[Optimization|clean-up]
>
> The string addition in the parameter will create another string buffer,
> append all the components, then convert that to a string so the you can be
> appended to your string buffer.
>
> So I replace this:
>
> sb.append(" xxx: [" + getXXX() + "]\n");
>
> for this:
>
> sb.append(" xxx: [").append(getXXX()).append("]\n");
Hmm. I wonder that a JIT can't do this automatically. Perhaps
it already does; I haven't looked.
Andrew.
More information about the core-libs-dev
mailing list