diff options
author | Lukas Rytz <lukas.rytz@typesafe.com> | 2014-12-04 17:59:37 +0100 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2014-12-04 17:59:37 +0100 |
commit | ff4d3d2b57df5b4e5c00ce088b7b1fe321f11231 (patch) | |
tree | 73a14bb9fec316dea414584ab33ec9b73104c7a5 | |
parent | 3b1ac0671909fef8a4aef35d62a3dc7fd7d98d9d (diff) | |
parent | d3bd2b7463d7f187fe45e54b503f99e183480a52 (diff) | |
download | scala-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
-rwxr-xr-x | src/library/scala/collection/LinearSeqOptimized.scala | 15 |
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) } |