Thursday, May 27, 2010

Re: Fastest way to create lots of similar elements

Hi George,

absolutely - the other browsers are fine with simple DOM manipulation.

Inspired by the (a little bit outdated) benchmark [1], I changed my
code to join arrays instead of strings:

--------------
void attachImages(...) {
final JsArrayString array = JavaScriptObject.createArray().cast();
for (...) {
boolean flag = ...;
array.push(flag ? "<img src='images/a.gif' style='left:" : "<img
src='images/b.gif' style='top:");
array.push(String.valueOf(i));
array.push("em'/>");
}
div1.setHTML(array.join(""));
}

--------------

This also only calls setHTML() once at the end of the loop.

Does anybody see possibilities for optimization - either improving
performance or resulting in cleaner code?

[1]: http://www.quirksmode.org/dom/innerhtml.html


On May 28, 12:31 am, George Georgovassilis
<g.georgovassi...@gmail.com> wrote:
> Hello Chris,
>
> I think, especially with respect to IE, the fastest way is still to
> construct a string and assign it to div's innerHTML... provided that
> you can find an intelligent and fast way to create that string, as IE
> (at least prior to 8) has a notoriously slow string concatenation.
>
> On May 27, 9:33 pm, Chris Lercher <cl_for_mail...@gmx.net> wrote:

--
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-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment