Created
April 8, 2012 14:11
-
-
Save nobeans/2337510 to your computer and use it in GitHub Desktop.
Summarized and translated my tweets about groovy at 2012-04-07
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When I decompiled a compiled code with @CompileStatic, I found something there: | |
- @TypeChecked annotations there. (it's good) | |
- compareTo was compiled as primitive code instead of a call of ScriptBytecodeAdapter. | |
- There are unnecessary null in places. | |
- The decompiled result seems curious. It's a little inefficient. | |
- By Groovy++: (right.getColor()==BLACK) | |
- By Groovy2.0b @CompileStatic: ((right.color==BLACK ? 1 : 0) !=0) | |
-------------- | |
Groovy source: | |
-------------- | |
import groovy.transform.CompileStatic | |
@CompileStatic | |
class Simple { | |
def method(int a, int b, int c) { | |
if (a == 1 || b == 1 || c == 1) { | |
return true | |
} | |
return false | |
} | |
} | |
-------------- | |
Decompiled of the class copmiled with CompileStatic: | |
-------------- | |
import groovy.lang.GroovyObject; | |
import groovy.lang.MetaClass; | |
import groovy.transform.TypeChecked.TypeCheckingInfo; | |
public class Simple | |
implements GroovyObject | |
{ | |
public Simple() | |
{ | |
Simple this; | |
MetaClass localMetaClass = $getStaticMetaClass(); | |
this.metaClass = localMetaClass; | |
} | |
@TypeChecked.TypeCheckingInfo(inferredType="AAlDbGFzc05vZGUAAAFaAP////8=", version=1) | |
public Object method(int a, int b, int c) | |
{ | |
if (((a == 1) ? 1 : 0) == 0); | |
if (((((b == 1) ? 1 : 0) != 0) ? 1 : 0) == 0); | |
if (((((c == 1) ? 1 : 0) != 0) ? 1 : 0) != 0) { //------[1] | |
return Boolean.valueOf(true); | |
} | |
return Boolean.valueOf(false); return null; // ----[2] | |
} | |
static | |
{ | |
__$swapInit(); | |
long l1 = 0L; | |
__timeStamp__239_neverHappen1333898122602 = l1; | |
long l2 = 1333898122602L; | |
__timeStamp = l2; | |
} | |
} | |
-------------- | |
Tests | |
-------------- | |
import spock.lang.* | |
class SimpleSpec extends Specification { | |
def simple | |
def setup() { | |
simple = new Simple() | |
} | |
def ""() { | |
expect: | |
simple.method(a, b, c) == result | |
where: | |
a | b | c | result | |
0 | 0 | 0 | false | |
0 | 0 | 1 | true | |
0 | 1 | 1 | true | |
1 | 1 | 1 | true | |
1 | 0 | 0 | true | |
0 | 1 | 0 | true | |
0 | 0 | 1 | true | |
} | |
} | |
-------------- | |
[1] is the very curious, but tests are all green... | |
2nd return of [2] is unnecessary. | |
*** | |
A performance of latest HEAD of master (0c2b64) without indy option is almost as same as released 1.8.6. | |
@StaticCompile's performance is ten times faster than them, and almost as same as Groovy++'s one. It's great work! | |
And now, I don't know the usage of indy option... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've caught the flu since Friday...