The foreach loop in normal Java will also construct an Iterator object, and 
therefore is almost 
always more expensive than a for-index-loop (assuming the Collection is 
random-access).

I would really call this a premature optimization, but if you're really 
concerned with such things, 
the (technically) fastest way of doing this would be:

final int length = list.size();
for(int i = 0; i < length; i++) {
        Foo foo = list.get(i);
}

That applies for normal Java, for GWT the final is not required (since it has 
no affect on the 
output, and the compiler will declare it final anyways).

Again, serious micro-optimization that will make very little difference in the 
long run.

Ed wrote:
> Hellu,
> 
> Should I use the foreach or for-index-loop construction?
> Is GWT smart enough to implement the best solution?
> Can I simple neglect the difference in performance ?
> 
> I mean: in the Google IO presentation  they mentioned that the foreach
> construction creates a new Iterator object and as such is a bit more
> expensive. As such they used the for-index-loop construction. ... I
> can imagine when performing many foreach loops, this can become an
> issue.
> 
> Ed
> > 
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to