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

Optimise bytecode for empty list expressions

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.5.23, 3.0.20, 4.0.18, 5.0.0-alpha-5
    • None
    • None

    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

              Unassigned Unassigned
              paint_ninja Oscar N
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: