Skip to content

List(...) builder missing Scala 2 optimization to avoid intermediate array #17035

Closed
@armanbilge

Description

@armanbilge

Compiler version

3.3.1-RC1-bin-20230301-0df5ae2-NIGHTLY

Minimized code

class Test {
  def foo = List("foo", "bar", "baz")
}

Output

/*
 * Decompiled with CFR 0.151.
 */
import scala.collection.immutable.List;
import scala.collection.immutable.Seq;
import scala.package$;
import scala.runtime.ScalaRunTime$;

public class Test {
    public List<String> foo() {
        return (List)package$.MODULE$.List().apply((Seq)ScalaRunTime$.MODULE$.wrapRefArray((Object[])new String[]{"foo", "bar", "baz"}));
    }
}

Expectation

The List is built directly, without going through an intermediate varargs array.

Scala 2.13.10 decompiles to this:

/*
 * Decompiled with CFR 0.151.
 */
import scala.collection.immutable.;
import scala.collection.immutable.List;
import scala.collection.immutable.Nil$;

public class Test {
    public List<String> foo() {
        return new .colon.colon((Object)"foo", (List)new .colon.colon((Object)"bar", (List)new .colon.colon((Object)"baz", (List)Nil$.MODULE$)));
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions