8000 Specialize genTraversableOnce2jsArray for js.ArrayOps and js.WrappedA… · scala-js/scala-js@0d2402b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d2402b

Browse files
committed
Specialize genTraversableOnce2jsArray for js.ArrayOps and js.WrappedArray.
In a sense, this is as if .toJSArray were overridden in js.ArrayOps and js.WrappedArray, which makes total sense. But since .toJSArray is a pimp, we need to make this specialization directly in its implementation.
1 parent 277b4ad commit 0d2402b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

library/src/main/scala/scala/scalajs/runtime/package.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ package object runtime {
66

77
@inline final def genTraversableOnce2jsArray[A](
88
col: GenTraversableOnce[A]): js.Array[A] = {
9-
val result = new js.Array[A]
10-
col.foreach(x => result.push(x))
11-
result
9+
col match {
10+
case col: js.ArrayOps[A] => col.result()
11+
case col: js.WrappedArray[A] => col.array
12+
case _ =>
13+
val result = new js.Array[A]
14+
col.foreach(x => result.push(x))
15+
result
16+
}
1217
}
1318

1419
/** Information about the environment Scala.js runs in. */

0 commit comments

Comments
 (0)
0