On 13 juil, 11:10, Manuel Carrasco Moñino <man...@apache.org> wrote:
> I've not checked the code produced by the Gwt compiler, but I think it
> could introduce a bit of overhead or may be none (if the
> implementation code was 100% optimal).
> Anyway the use of String should guarantee that the final code is
> faster or equal.

That's wrong. StringBuilder will use either string concatenation (in
which case you'll suffer a very small, and negligible, penalty at
runtime) or array-append-then-join, depending on which method was
benchmarked the fastest in each browser.
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/super/com/google/gwt/emul/EmulationWithUserAgent.gwt.xml
The GWT has experimented with many options before settling on these
two: using a.push() or a[arrayLength++] to append to an array, using
join() or String.prototype.concat.apply() to join the array items into
a string, etc. you'll find them all in the subversion repository:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/core/client/impl/
Note that string concatenation is done using the += operator, which is
more performant than s = s + something in some browsers (AFAIK).

So really, GWT is optimized here, and you shouldn't fear from using
StringBuilder (or StringBuffer) if you think they're necessary (of
course, when concatenating 3 strings, it might not be worth it;
StringBuilder is mostly useful with loops and/or building large
strings, and this is true in both Java and GWT)

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to