From 3eadba0dddb50a54aa4bf11b34768b51694e03e0 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 16 Jul 2009 20:31:24 +0000 Subject: scala> List(1,2,3) endsWith List(2, "I AM GOZER... scala> List(1,2,3) endsWith List(2, "I AM GOZER THE DESTROYER") res0: Boolean = true ... is fixed. --- .../scala/collection/generic/SequenceTemplate.scala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/library/scala/collection/generic/SequenceTemplate.scala b/src/library/scala/collection/generic/SequenceTemplate.scala index ba949152bd..df49b442bb 100644 --- a/src/library/scala/collection/generic/SequenceTemplate.scala +++ b/src/library/scala/collection/generic/SequenceTemplate.scala @@ -283,11 +283,12 @@ trait SequenceTemplate[+A, +This <: IterableTemplate[A, This] with Sequence[A]] * @see String.startsWith */ def startsWith[B](that: Sequence[B], offset: Int): Boolean = { - val i = this.iterator.drop(offset) + val i = this.iterator drop offset val j = that.iterator - while (j.hasNext && i.hasNext) { - if (i.next != j.next) return false - } + while (j.hasNext && i.hasNext) + if (i.next != j.next) + return false + !j.hasNext } @@ -305,7 +306,10 @@ trait SequenceTemplate[+A, +This <: IterableTemplate[A, This] with Sequence[A]] def endsWith[B](that: Sequence[B]): Boolean = { val i = this.iterator.drop(length - that.length) val j = that.iterator - while (i.hasNext && j.hasNext && i.next == j.next) () + while (i.hasNext && j.hasNext) + if (i.next != j.next) + return false + !j.hasNext } -- cgit v1.2.3