Skip to content

Commit 58119a3

Browse files
authored
Merge pull request #192 from szeiger/wip/arrayseq-fixes
Backport immutable.ArraySeq bug fixes from Scala 2.13
2 parents 8e3728b + de163b8 commit 58119a3

File tree

1 file changed

+19
-3
lines changed
  • compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable

1 file changed

+19
-3
lines changed

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

+19-3
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ object ArraySeq {
113113
override def hashCode = MurmurHash3.arrayHash(unsafeArray, MurmurHash3.seqSeed)
114114
override def equals(that: Any) = that match {
115115
case that: ofRef[_] =>
116-
Arrays.equals(unsafeArray.asInstanceOf[Array[AnyRef]],
117-
that.unsafeArray.asInstanceOf[Array[AnyRef]])
116+
arrayEquals(unsafeArray.asInstanceOf[Array[AnyRef]],
117+
that.unsafeArray.asInstanceOf[Array[AnyRef]])
118118
case _ => super.equals(that)
119119
}
120120
}
@@ -125,7 +125,7 @@ object ArraySeq {
125125
def length: Int = unsafeArray.length
126126
def apply(index: Int): Byte = unsafeArray(index)
127127
def update(index: Int, elem: Byte) { unsafeArray(index) = elem }
128-
override def hashCode = MurmurHash3.bytesHash(unsafeArray, MurmurHash3.seqSeed)
128+
override def hashCode = MurmurHash3.arrayHash(unsafeArray, MurmurHash3.seqSeed)
129129
override def equals(that: Any) = that match {
130130
case that: ofByte => Arrays.equals(unsafeArray, that.unsafeArray)
131131
case _ => super.equals(that)
@@ -237,4 +237,20 @@ object ArraySeq {
237237
case _ => super.equals(that)
238238
}
239239
}
240+
241+
private[this] def arrayEquals(xs: Array[AnyRef], ys: Array[AnyRef]): Boolean = {
242+
if (xs eq ys)
243+
return true
244+
if (xs.length != ys.length)
245+
return false
246+
247+
val len = xs.length
248+
var i = 0
249+
while (i < len) {
250+
if (xs(i) != ys(i))
251+
return false
252+
i += 1
253+
}
254+
true
255+
}
240256
}

0 commit comments

Comments
 (0)