Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.5.7, 1.6-beta-2
-
None
-
All
Description
given the following loop:
while(true) {
}
generates the following bytecode:
48: getstatic #61; //Field java/lang/Boolean.TRUE:Ljava/lang/Boolean;
51: invokestatic #67; //Method org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.booleanUnbox:(Ljava/lang/Object;)Z
54: ifeq 60
57: goto 48
javac performs one of two optimization here depending on the body of the loop, which groovyc could easily do as well.
1. If the body of the loop is empty, don't generate any bytecode at all.
2. If the body of the loop is non-empty, then simply generate a goto to jump to the top of the loop, there's no need to getstatic, invokestatic, and ifeq.
Since this kind of loop is a common idiom, it is worth optimizing in my opinion.