Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.3
Description
Groovy 2.4.3 generates not the most efficient 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 efficient 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 ()))))
Attachments
Issue Links
- is related to
-
GROOVY-6137 CompileStatic: in operator (isCase) isn't null safe in CS mode
- Closed
- relates to
-
GROOVY-10909 bytecode for in, !in, !() and ?:
- Closed