summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@epfl.ch>2009-02-17 20:03:07 +0000
committerLukas Rytz <lukas.rytz@epfl.ch>2009-02-17 20:03:07 +0000
commit0171fdede17e5340cc034c742a11e9f2a03c6042 (patch)
tree5ad113b9eee6669878854002d5e04e9c4817125a
parent0ee11c38762844fa78bf2fd0861680c4b6ac2e8e (diff)
downloadscala-0171fdede17e5340cc034c742a11e9f2a03c6042.tar.gz
scala-0171fdede17e5340cc034c742a11e9f2a03c6042.tar.bz2
scala-0171fdede17e5340cc034c742a11e9f2a03c6042.zip
fix for #1721
-rw-r--r--src/library/scala/Seq.scala11
-rw-r--r--test/files/run/lists.scala16
2 files changed, 17 insertions, 10 deletions
diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala
index 0d1306b07f..18b8dac676 100644
--- a/src/library/scala/Seq.scala
+++ b/src/library/scala/Seq.scala
@@ -470,15 +470,8 @@ trait Seq[+A] extends AnyRef with PartialFunction[Int, A] with Collection[A] {
/** @return true if this sequence end with that sequence
* @see String.endsWith
*/
- def endsWith[B](that: Seq[B]): Boolean = {
- val length = this.length
- val j = that.elements
- var i = 0
- var result = true
- while (result && i < length && j.hasNext)
- result = apply(length - i - 1) == j.next
- result && !j.hasNext
- }
+ def endsWith[B](that: Seq[B]): Boolean =
+ drop(length - that.length).sameElements(that)
/**
* Searches for the argument sequence in the receiver object, returning
diff --git a/test/files/run/lists.scala b/test/files/run/lists.scala
index 665cf51970..93848da25f 100644
--- a/test/files/run/lists.scala
+++ b/test/files/run/lists.scala
@@ -15,7 +15,8 @@ object Test extends TestConsoleMain {
def suite = new TestSuite(
Test1, //count, exists, filter, ..
Test2, //#468
- Test3 //#1691
+ Test3, //#1691
+ Test4 //#1721
)
}
@@ -126,3 +127,16 @@ object Test3 extends TestCase("t1691") with Assert {
List(10, 8, 6, 4, 2))
}
}
+
+object Test4 extends TestCase("t1721") with Assert {
+ override def enableStackTrace = false
+ override def runTest {
+ assertTrue(List(1,2,3).endsWith(List(2,3)))
+ assertFalse(List(1,2,3).endsWith(List(1,3)))
+ assertTrue(List(1,2,3).endsWith(List()))
+ assertFalse(List(1,2,3).endsWith(List(0,1,2,3)))
+ assertTrue(List(1,2,3).endsWith(List(1,2,3)))
+ assertFalse(List().endsWith(List(1,2,3)))
+ assertTrue(List().endsWith(List()))
+ }
+}