On Wed, Oct 5, 2011 at 12:10 PM, Axel Rauschmayer <a...@rauschma.de> wrote:

>  The two concatenation approaches I know of are:
>> 1. via +=
>> 2. push() into an array, join() it after the last push()
>>
>> (1) can’t possibly be efficient,
>
>
> Huh? Engines have optimized the hell out of 1 by essentially doing 2 under
> the hood. Even rhino's about a land a patch to do just that.
>
>
>> but if (2) is OK on all(!) platforms, then a library would be OK. However,
>> given how frequently this is used, I would like this to become part of the
>> standard library.
>>
>
> What exactly do you want supported?
>
>
> Something like Java’s StringBuilder. If, however, (2) collects the
> concatenated substrings and only joins them on demand in current engines,
> then there is indeed no need for such a thing.
>

GWT's implementation of StringBuilder actually uses both methods #1 and #2
under the hood, because each is faster on different browsers (due to
deferred binding, you only get the implementation for the browser you are
using and parts of it can be inlined at call sites so you don't pay the
penalty for multiple implementations).

-- 
John A. Tamplin
Software Engineer (GWT), Google
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to