diff options
Diffstat (limited to 'src')
-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) } |