Skip to content

Commit

Permalink
Merge pull request #192 from szeiger/wip/arrayseq-fixes
Browse files Browse the repository at this point in the history
Backport immutable.ArraySeq bug fixes from Scala 2.13
  • Loading branch information
szeiger authored Apr 7, 2019
2 parents 8e3728b + de163b8 commit 58119a3
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ object ArraySeq {
override def hashCode = MurmurHash3.arrayHash(unsafeArray, MurmurHash3.seqSeed)
override def equals(that: Any) = that match {
case that: ofRef[_] =>
Arrays.equals(unsafeArray.asInstanceOf[Array[AnyRef]],
that.unsafeArray.asInstanceOf[Array[AnyRef]])
arrayEquals(unsafeArray.asInstanceOf[Array[AnyRef]],
that.unsafeArray.asInstanceOf[Array[AnyRef]])
case _ => super.equals(that)
}
}
Expand All @@ -125,7 +125,7 @@ object ArraySeq {
def length: Int = unsafeArray.length
def apply(index: Int): Byte = unsafeArray(index)
def update(index: Int, elem: Byte) { unsafeArray(index) = elem }
override def hashCode = MurmurHash3.bytesHash(unsafeArray, MurmurHash3.seqSeed)
override def hashCode = MurmurHash3.arrayHash(unsafeArray, MurmurHash3.seqSeed)
override def equals(that: Any) = that match {
case that: ofByte => Arrays.equals(unsafeArray, that.unsafeArray)
case _ => super.equals(that)
Expand Down Expand Up @@ -237,4 +237,20 @@ object ArraySeq {
case _ => super.equals(that)
}
}

private[this] def arrayEquals(xs: Array[AnyRef], ys: Array[AnyRef]): Boolean = {
if (xs eq ys)
return true
if (xs.length != ys.length)
return false

val len = xs.length
var i = 0
while (i < len) {
if (xs(i) != ys(i))
return false
i += 1
}
true
}
}

0 comments on commit 58119a3

Please sign in to comment.