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

Optimise bytecode for empty list expressions

    XMLWordPrintableJSON

Details

    Description

      I have the following code:

      class Book {
          String title
          String blurb = ''
          List<String> authors = []
      }
      

      When checking the compiled output, the creation of the empty list goes through ScriptBytecodeAdapter:

      @Generated
      public Book() {
          String var1 = "";
          this.blurb = var1;
          List var2 = ScriptBytecodeAdapter.createList(new Object[0]);
          this.authors = var2;
          MetaClass var3 = this.$getStaticMetaClass();
          this.metaClass = var3;
      }
      

      This case can be simplified to "List var2 = new ArrayList()", which would avoid some overhead and slightly improve @POJO support.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              paint_ninja Oscar N
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: