Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.5.1
-
None
-
Java: 1.6.0_03
Ant: 1.6.5
WindowsXP SP2
Description
Part 1:
If I build my software with the groovyc ant task I see that closures are compiled twice. I've attached a test project. You'll see that closure1 .. closure4 are generated, but there are only 2 closures in the groovy class.
If I remove the java class, the problem is gone.
I've also decompiled the constructor:
public Test1() { super(); class1 = Test1.class$0 == null ? ( Test1.class$0 = Test1.class$( "app.Test1" ) ) : Test1.class$0; class2 = Test1.class$groovy$lang$MetaClass == null ? ( Test1.class$groovy$lang$MetaClass = Test1.class$( "groovy.lang.MetaClass" ) ) : Test1.class$groovy$lang$MetaClass; this.index = new _closure1( this, this ); this.search = new _closure2( this, this ); this.metaClass = (MetaClass)ScriptBytecodeAdapter.castToType( (MetaClass)ScriptBytecodeAdapter.castToType( ScriptBytecodeAdapter.invokeStaticMethodN( class1, Test1.class$org$codehaus$groovy$runtime$ScriptBytecodeAdapter == null ? ( Test1.class$org$codehaus$groovy$runtime$ScriptBytecodeAdapter = Test1.class$( "org.codehaus.groovy.runtime.ScriptBytecodeAdapter" ) ) : Test1.class$org$codehaus$groovy$runtime$ScriptBytecodeAdapter, "initMetaClass", new Object[] { this } ), class2 ), class2 ); this.index = new _closure3( this, this ); this.search = new _closure4( this, this ); this.metaClass = (MetaClass)ScriptBytecodeAdapter.castToType( (MetaClass)ScriptBytecodeAdapter.castToType( ScriptBytecodeAdapter.invokeStaticMethodN( class1, Test1.class$org$codehaus$groovy$runtime$ScriptBytecodeAdapter == null ? ( Test1.class$org$codehaus$groovy$runtime$ScriptBytecodeAdapter = Test1.class$( "org.codehaus.groovy.runtime.ScriptBytecodeAdapter" ) ) : Test1.class$org$codehaus$groovy$runtime$ScriptBytecodeAdapter, "initMetaClass", new Object[] { this } ), class2 ), class2 ); return; }
Here you see that the index, search and metaClass fields are set twice. 4 closures are instantiated.
Part 2:
Furthermore you see that the (MetaClass)ScriptBytecodeAdapter.castToType() method is called twice. The looks a bit overkill. This is done like this in a lot of other methods of the class too: getMetaClass, invokeMethod, getProperty, setProperty. This has negative influence on performance.
Part 3:
In the generated getters and setters you will also see that 2 classes are retrieved into 2 local variables although they are not used. This has negative influence on performance too.
I've attached the complete decompiled class.