summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2014-12-04 17:59:37 +0100
committerLukas Rytz <lukas.rytz@typesafe.com>2014-12-04 17:59:37 +0100
commitff4d3d2b57df5b4e5c00ce088b7b1fe321f11231 (patch)
tree73a14bb9fec316dea414584ab33ec9b73104c7a5 /src/library
parent3b1ac0671909fef8a4aef35d62a3dc7fd7d98d9d (diff)
parentd3bd2b7463d7f187fe45e54b503f99e183480a52 (diff)
downloadscala-ff4d3d2b57df5b4e5c00ce088b7b1fe321f11231.tar.gz
scala-ff4d3d2b57df5b4e5c00ce088b7b1fe321f11231.tar.bz2
scala-ff4d3d2b57df5b4e5c00ce088b7b1fe321f11231.zip
Merge pull request #4168 from Ichoran/issue/9000
SI-9000 equals for immutable collections should check identity
Diffstat (limited to 'src/library')
-rwxr-xr-xsrc/library/scala/collection/LinearSeqOptimized.scala15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/library/scala/collection/LinearSeqOptimized.scala b/src/library/scala/collection/LinearSeqOptimized.scala
index f834545ec6..64248aa755 100755
--- a/src/library/scala/collection/LinearSeqOptimized.scala
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -249,13 +249,16 @@ trait LinearSeqOptimized[+A, +Repr <: LinearSeqOptimized[A, Repr]] extends Linea
override /*IterableLike*/
def sameElements[B >: A](that: GenIterable[B]): Boolean = that match {
case that1: LinearSeq[_] =>
- var these = this
- var those = that1
- while (!these.isEmpty && !those.isEmpty && these.head == those.head) {
- these = these.tail
- those = those.tail
+ // Probably immutable, so check reference identity first (it's quick anyway)
+ (this eq that1) || {
+ var these = this
+ var those = that1
+ while (!these.isEmpty && !those.isEmpty && these.head == those.head) {
+ these = these.tail
+ those = those.tail
+ }
+ these.isEmpty && those.isEmpty
}
- these.isEmpty && those.isEmpty
case _ =>
super.sameElements(that)
}