Top 5

Denis Koroskin 2korden at gmail.com
Fri Oct 10 08:31:48 PDT 2008


On Fri, 10 Oct 2008 19:19:45 +0400, Sergey Gromov <snake.scaly at gmail.com>  
wrote:

> Fri, 10 Oct 2008 19:10:19 +0400,
> Denis Koroskin wrote:
>> On Fri, 10 Oct 2008 18:33:43 +0400, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>> > Sergey Gromov wrote:
>> >> I'd also like
>> >>   "foo" ~ text ~ "bar"
>> >> to become something like
>> >>   (new Array!(char)) ~= "foo" ~= text ~= "bar"
>> >> that is what Java does to string concatenation.  Sugar doesn't seem  
>> to
>> >> couple well with a purely library type.
>>
>> I doubt that. Java strings are immutable, their length can't be changed
>> either (i.e. they are a direct analog of a proposed invariant(char)[]).
>> Concatanating Java strings don't turn them into array, and it is dead
>> slow. Every sane person uses StringBuilder instead.
>
> Java compiler substitutes
>
> "foo" + text + "bar"
>
> with
>
> new StringBuilder().append("foo").append(text).append("bar").toString()
>
> all by itself because both String and StringBuilder are built-in
> classes.

Yes, you are right. From The Java Language Specification, 3rd edition:

> To increase the performance of repeated string concatenation,
> a Java compiler may use the StringBuffer class or a similar technique
> to reduce the number of intermediate String objects that are created
> by evaluation of an expression.



More information about the Digitalmars-d mailing list