I have just downloaded 1.5 and started playing with it.
I made a small test with the new enhanced loops. So far I thought it was just a syntax improvment. I did not realize it can help improve the performance of loops also. Isn’t that cool or did I just wake up after everybody ?
Before 1.5, one would write (some stupid test) like this:
// array is int[]
for (int i=0, n=array.length; i<n; i++)
{
int p = array[i];
p=p+p+p;
}
in 1.5, it becomes:
for (int p : array)
{
p=p+p+p;
}
There is no penalty access to the elements of the array and my first tests show it is actually faster (and yes it is a micro benchmark however it have some audio processing code with tight loops goobling most of the processing time). I wonder if the JVM also can optimize the bound checks since it ‘knows’ that the whole array is going to be scanned ?