Brian Jones wrote:
> 
> [EMAIL PROTECTED] writes:
> 
> > This means that instead of writing:
> > for(int i=0; i<constant; i++) write:
> > for(int i=constant-1; i>=0; i--)
> 
> This makes assumptions about the use of the variable `i'.
> 
> It could be written as "for(int i=constant-1; i>-1; i--)"

Original one is faster - vm can use
iload_n (i variable)
ifge

instead of

iload_n
iconst_m1
ifcmp_gt

But generally such optimizations should be done by jit. As long as
constant is really constant it can be done. In other case example yoy
provided is better - because it doesn't allow modification of loop
treshold from within loop (thing possible with not-constant 'constant')

Artur

Reply via email to