diff options
author | Paul Phillips <paulp@improving.org> | 2009-07-16 21:10:22 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-07-16 21:10:22 +0000 |
commit | 35a638ed93eb5651ff93e90422741e740e985f5e (patch) | |
tree | 7d81b54f8e52c7da7fb67efb9fe2e68433db95b8 | |
parent | 3eadba0dddb50a54aa4bf11b34768b51694e03e0 (diff) | |
download | scala-35a638ed93eb5651ff93e90422741e740e985f5e.tar.gz scala-35a638ed93eb5651ff93e90422741e740e985f5e.tar.bz2 scala-35a638ed93eb5651ff93e90422741e740e985f5e.zip |
scala> immutable.Vector(1,2,3) endsWith immutab...
scala> immutable.Vector(1,2,3) endsWith immutable.Vector(2,3)
res0: Boolean = false
...is fixed.
-rw-r--r-- | src/library/scala/collection/generic/IterableTemplate.scala | 10 | ||||
-rw-r--r-- | src/library/scala/collection/generic/VectorTemplate.scala | 19 |
2 files changed, 16 insertions, 13 deletions
diff --git a/src/library/scala/collection/generic/IterableTemplate.scala b/src/library/scala/collection/generic/IterableTemplate.scala index 442043a14e..b0555df124 100644 --- a/src/library/scala/collection/generic/IterableTemplate.scala +++ b/src/library/scala/collection/generic/IterableTemplate.scala @@ -156,11 +156,11 @@ trait IterableTemplate[+A, +This <: IterableTemplate[A, This] with Iterable[A]] def sameElements[B >: A](that: Iterable[B]): Boolean = { val these = this.iterator val those = that.iterator - var res = true - while (res && these.hasNext && those.hasNext) { - res = (these.next == those.next) - } - !these.hasNext && !those.hasNext && res + while (these.hasNext && those.hasNext) + if (these.next != those.next) + return false + + !these.hasNext && !those.hasNext } /** Returns a stream with all elements in this traversable object. diff --git a/src/library/scala/collection/generic/VectorTemplate.scala b/src/library/scala/collection/generic/VectorTemplate.scala index a656072ed2..5bcf3ba83f 100644 --- a/src/library/scala/collection/generic/VectorTemplate.scala +++ b/src/library/scala/collection/generic/VectorTemplate.scala @@ -238,15 +238,18 @@ trait VectorTemplate[+A, +This <: VectorTemplate[A, This] with Vector[A]] extend override def endsWith[B](that: Sequence[B]): Boolean = that match { case that: Vector[_] => - val thisLen = length - val thatLen = that.length - var i = thisLen - 1 - var j = thatLen - 1 - while (i >= 0 && j >= 0 && this(i) == that(j)) { - i -= 1 - j -= 1 + var i = length - 1 + var j = that.length - 1 + + (j <= i) && { + while (j >= 0) { + if (this(i) != that(j)) + return false + i -= 1 + j -= 1 + } + true } - j == 0 case _ => super.endsWith(that) } |