[ 
https://issues.apache.org/jira/browse/GROOVY-7473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14650165#comment-14650165
 ] 

Jochen Theodorou commented on GROOVY-7473:
------------------------------------------

Ok, I kind of forgot we are talking about static compilation and not standard 
Groovy. Because in standard Groovy you can do something like 
this:{code:Java}def bool1 = "s" in ["State1", "State2", "State3"]
ArrayList.metaClass.isCase = {Object o -> true}
def bool2 = "s" in ["State1", "State2", "State3"]
assert bool1 != bool2{code}
In such a case we would not be able to ensure the list is not modified. Now in 
static compilation runtime meta programming is of course not a deciding factor, 
but you can still have a different isCase method being applied, if you provide 
an extension method with fitting signature at compile time.

How is the compiler supposed to know it can make the list literal into 
something like a constant? So far your suggestion would mean a special case for 
list and isCase

> ineffient code generation
> -------------------------
>
>                 Key: GROOVY-7473
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7473
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.3
>            Reporter: Laurenz Tontsch
>              Labels: performance
>
> Groovy 2.4.3 generates not the most effient byte code of a simple statement 
> like "in".
> e.g. The following statement:
> If object.stringProperty in ["State1", "State2", "State3"
> gets complied in:
> if 
> (DefaultTypeTransformation.booleanUnbox((ScriptBytecodeAdapter.createList(new 
> Object[] { "State1", "State2", "State3" }) == null ? 1 : 0) != 0 ? 
> Boolean.valueOf(object.getStringProperty() == null) : 
> Boolean.valueOf(DefaultGroovyMethods.isCase(ScriptBytecodeAdapter.createList(new
>  Object[] { "State1", "State2 ", "State3" }), object. getStringProperty ()))))
> instead of this a more effient construct would be the usage of an static list
> e.g.
> static List<String> l1;
> static {
>         l1 = new LinkedList<String>();
>         l1.add("State1");
>         l1.add("State2");
>         l1.add("State3");
> }
> if (DefaultTypeTransformation.booleanUnbox((l1 == null ? 1 : 0) != 0 ? 
> Boolean.valueOf(object.getStringProperty() == null) : 
> Boolean.valueOf(DefaultGroovyMethods.isCase(l1, object. getStringProperty 
> ()))))



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to