On Mon, Jan 26, 2015 at 7:03 AM, Benedikt Ritter <[email protected]> wrote:
> Hello Adrian
>
> 2015-01-24 19:43 GMT+01:00 Adrian Crum <[email protected]>:
>
>> Slightly off-topic but somewhat related...
>>
>> I saw a recent commit where a "performance improvement" went something
>> like this:
>>
>> StringBuilder sb = new StringBuilder();
>> sb.append("foo");
>>
>> was replaced with
>>
>> StringBuilder sb = new StringBuilder("foo");
>>
>> The change reduced the code by one line, but there was no "performance
>> improvement" - because the StringBuilder constructor calls append().
>>
>
> All methods on StringBuffer are synchronized, so there a slight overhead of
> acquiring the lock. This is usually the argument for using StringBuilder
> over StringBuffer.
>

But, there was no StringBuffer referenced in the above code snippet,
right, so the sync vs. non-sync doesn't apply.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to