summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRex Kerr <ichoran@gmail.com>2014-11-21 17:48:18 -0800
committerRex Kerr <ichoran@gmail.com>2014-11-26 17:44:44 -0800
commitd3bd2b7463d7f187fe45e54b503f99e183480a52 (patch)
tree97bc0f2a65f954cd0fd47e55abe7475698f7d0fa
parent3ac6eabae685f08fb349ddab16cbaa1c6e97984b (diff)
downloadscala-d3bd2b7463d7f187fe45e54b503f99e183480a52.tar.gz
scala-d3bd2b7463d7f187fe45e54b503f99e183480a52.tar.bz2
scala-d3bd2b7463d7f187fe45e54b503f99e183480a52.zip
SI-9000 equals for immutable collections should check identity
`LinearSeqOptimized` now checks reference identity on `LinearSeq`s. No unit test; this doesn't change visible behavior (save for side-effecting equals methods).
-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 a28d796d5b..0f48d21b71 100755
--- a/src/library/scala/collection/LinearSeqOptimized.scala
+++ b/src/library/scala/collection/LinearSeqOptimized.scala
@@ -235,13 +235,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)
}