Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7473

inefficient code generation

    XMLWordPrintableJSON

Details

    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

          Activity

            People

              emilles Eric Milles
              l.tontsch Laurenz Tontsch
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: