Skip to content

Commit 635b349

Browse files
authored
Merge pull request scala#6771 from xuwei-k/ArraySeq-equals
override ArraySeq#equals for efficiency
2 parents 9db61ba + c3c44fa commit 635b349

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/library/scala/collection/immutable/ArraySeq.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ sealed abstract class ArraySeq[+A]
142142
}
143143

144144
override protected[this] def writeReplace(): AnyRef = this
145+
146+
override def equals(other: Any): Boolean = other match {
147+
case that: ArraySeq[_] if this.unsafeArray.length != that.unsafeArray.length =>
148+
false
149+
case _ =>
150+
super.equals(other)
151+
}
145152
}
146153

147154
/**

src/library/scala/collection/mutable/ArraySeq.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ abstract class ArraySeq[T]
7777
}
7878

7979
override protected[this] def writeReplace(): AnyRef = this
80+
81+
override def equals(other: Any): Boolean = other match {
82+
case that: ArraySeq[_] if this.array.length != that.array.length =>
83+
false
84+
case _ =>
85+
super.equals(other)
86+
}
8087
}
8188

8289
/** A companion object used to create instances of `ArraySeq`.

0 commit comments

Comments
 (0)