Skip to content

Optimize multi-dimensional array creation #11358

Open
@retronym

Description

@retronym

We could consider using:

  def ofDim[T](n1: Int, n2: Int)(implicit tag: ClassTag[T]): Array[Array[T]] = {
    java.lang.reflect.Array.newInstance(tag.runtimeClass, n1, n2).asInstanceOf[Array[Array[T]]]
  }

Or we could introduce an additional constructor to Array that allows multiple dimensions to be specified and then update the backend to emit multinewarray.

@DarkDimius implemented something along these lines in dotty:

scala/scala3@b2215ed
lampepfl/scala@4bf9759

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions