Skip to content

Commit e4e11e2

Browse files
authored
Merge pull request #26 from lrytz/m4
M4
2 parents c28d997 + 252e3b5 commit e4e11e2

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: scala
33
scala:
44
- 2.11.12
55
- 2.12.6
6-
- 2.13.0-pre-a002630
6+
- 2.13.0-M4
77
jdk:
88
- oraclejdk8
99
env:
@@ -21,9 +21,9 @@ env:
2121

2222
matrix:
2323
exclude:
24-
- scala: 2.13.0-pre-a002630
24+
- scala: 2.13.0-M4
2525
env: SCALAJS_VERSION=0.6.22
26-
- scala: 2.13.0-pre-a002630
26+
- scala: 2.13.0-M4
2727
env: SCALAJS_VERSION=1.0.0-M3
2828
include:
2929
- scala: 2.12.6

build.sbt

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import sbtcrossproject.{crossProject, CrossType}
22
import ScalaModulePlugin._
33

44
inThisBuild(Seq(
5-
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
6-
crossScalaVersions := Seq("2.12.6", "2.13.0-pre-a002630", "2.11.12")
5+
crossScalaVersions := Seq("2.12.6", "2.13.0-M4", "2.11.12")
76
))
87

98
lazy val `scala-collection-compat` = crossProject(JSPlatform, JVMPlatform)

scalafix/build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ lazy val input = project
2323
lazy val output = project
2424
.settings(
2525
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
26-
scalaVersion := "2.13.0-pre-a002630"
26+
scalaVersion := "2.13.0-M4"
2727
)
2828

2929
lazy val tests = project

src/main/scala-2.11_2.12/scala/collection/immutable/ArraySeq.scala

+23-6
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,19 @@ object ArraySeq {
6464
private val EmptyArraySeq = new ofRef[AnyRef](new Array[AnyRef](0))
6565
def empty[T <: AnyRef]: ArraySeq[T] = EmptyArraySeq.asInstanceOf[ArraySeq[T]]
6666

67-
// If make is called explicitly we use whatever we're given, even if it's
68-
// empty. This may be unnecessary (if ArraySeq is to honor the collections
69-
// contract all empty ones must be equal, so discriminating based on the reference
70-
// equality of an empty array should not come up) but we may as well be
71-
// conservative since wrapRefArray contributes most of the unnecessary allocations.
72-
def unsafeWrapArray[T](x: AnyRef): ArraySeq[T] = (x match {
67+
/**
68+
* Wrap an existing `Array` into an `ArraySeq` of the proper primitive specialization type
69+
* without copying.
70+
*
71+
* Note that an array containing boxed primitives can be wrapped in an `ArraySeq` without
72+
* copying. For example, `val a: Array[Any] = Array(1)` is an array of `Object` at runtime,
73+
* containing `Integer`s. An `ArraySeq[Int]` can be obtained with a cast:
74+
* `ArraySeq.unsafeWrapArray(a).asInstanceOf[ArraySeq[Int]]`. The values are still
75+
* boxed, the resulting instance is an [[ArraySeq.ofRef]]. Writing
76+
* `ArraySeq.unsafeWrapArray(a.asInstanceOf[Array[Int]])` does not work, it throws a
77+
* `ClassCastException` at runtime.
78+
*/
79+
def unsafeWrapArray[T](x: Array[T]): ArraySeq[T] = (x.asInstanceOf[Array[_]] match {
7380
case null => null
7481
case x: Array[AnyRef] => new ofRef[AnyRef](x)
7582
case x: Array[Int] => new ofInt(x)
@@ -91,6 +98,7 @@ object ArraySeq {
9198
ArrayBuilder.make[T]()(m) mapResult ArraySeq.unsafeWrapArray[T]
9299
}
93100

101+
@SerialVersionUID(3L)
94102
final class ofRef[T <: AnyRef](val unsafeArray: Array[T]) extends ArraySeq[T] with Serializable {
95103
lazy val elemTag = ClassTag[T](unsafeArray.getClass.getComponentType)
96104
def length: Int = unsafeArray.length
@@ -103,6 +111,7 @@ object ArraySeq {
103111
}
104112
}
105113

114+
@SerialVersionUID(3L)
106115
final class ofByte(val unsafeArray: Array[Byte]) extends ArraySeq[Byte] with Serializable {
107116
def elemTag = ClassTag.Byte
108117
def length: Int = unsafeArray.length
@@ -115,6 +124,7 @@ object ArraySeq {
115124
}
116125
}
117126

127+
@SerialVersionUID(3L)
118128
final class ofShort(val unsafeArray: Array[Short]) extends ArraySeq[Short] with Serializable {
119129
def elemTag = ClassTag.Short
120130
def length: Int = unsafeArray.length
@@ -127,6 +137,7 @@ object ArraySeq {
127137
}
128138
}
129139

140+
@SerialVersionUID(3L)
130141
final class ofChar(val unsafeArray: Array[Char]) extends ArraySeq[Char] with Serializable {
131142
def elemTag = ClassTag.Char
132143
def length: Int = unsafeArray.length
@@ -139,6 +150,7 @@ object ArraySeq {
139150
}
140151
}
141152

153+
@SerialVersionUID(3L)
142154
final class ofInt(val unsafeArray: Array[Int]) extends ArraySeq[Int] with Serializable {
143155
def elemTag = ClassTag.Int
144156
def length: Int = unsafeArray.length
@@ -151,6 +163,7 @@ object ArraySeq {
151163
}
152164
}
153165

166+
@SerialVersionUID(3L)
154167
final class ofLong(val unsafeArray: Array[Long]) extends ArraySeq[Long] with Serializable {
155168
def elemTag = ClassTag.Long
156169
def length: Int = unsafeArray.length
@@ -163,6 +176,7 @@ object ArraySeq {
163176
}
164177
}
165178

179+
@SerialVersionUID(3L)
166180
final class ofFloat(val unsafeArray: Array[Float]) extends ArraySeq[Float] with Serializable {
167181
def elemTag = ClassTag.Float
168182
def length: Int = unsafeArray.length
@@ -175,6 +189,7 @@ object ArraySeq {
175189
}
176190
}
177191

192+
@SerialVersionUID(3L)
178193
final class ofDouble(val unsafeArray: Array[Double]) extends ArraySeq[Double] with Serializable {
179194
def elemTag = ClassTag.Double
180195
def length: Int = unsafeArray.length
@@ -187,6 +202,7 @@ object ArraySeq {
187202
}
188203
}
189204

205+
@SerialVersionUID(3L)
190206
final class ofBoolean(val unsafeArray: Array[Boolean]) extends ArraySeq[Boolean] with Serializable {
191207
def elemTag = ClassTag.Boolean
192208
def length: Int = unsafeArray.length
@@ -199,6 +215,7 @@ object ArraySeq {
199215
}
200216
}
201217

218+
@SerialVersionUID(3L)
202219
final class ofUnit(val unsafeArray: Array[Unit]) extends ArraySeq[Unit] with Serializable {
203220
def elemTag = ClassTag.Unit
204221
def length: Int = unsafeArray.length

0 commit comments

Comments
 (0)