diff options
author | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-08-07 09:05:01 +0000 |
---|---|---|
committer | Sean McDirmid <sean.mcdirmid@gmail.com> | 2007-08-07 09:05:01 +0000 |
commit | a19af644d2a04ddaaa93252b33795debdcda7057 (patch) | |
tree | f3c021766b7ebf07239175c32779b7c47bc194a0 /src/library | |
parent | fe133c86f413abc789164619221bf560b97531b1 (diff) | |
download | scala-a19af644d2a04ddaaa93252b33795debdcda7057.tar.gz scala-a19af644d2a04ddaaa93252b33795debdcda7057.tar.bz2 scala-a19af644d2a04ddaaa93252b33795debdcda7057.zip |
Fixing indexOf bug.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Seq.scala | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/library/scala/Seq.scala b/src/library/scala/Seq.scala index a076cbf2ef..b78c3f9123 100644 --- a/src/library/scala/Seq.scala +++ b/src/library/scala/Seq.scala @@ -412,19 +412,21 @@ trait Seq[+A] extends AnyRef with PartialFunction[Int, A] with Collection[A] { /** @returns -1 if <code>that</code> not contained in this, otherwise the index where <code>that</code> is contained * @see String.indexOf */ - def indexOf[B](that : Seq[B]) : Int = { - val i = this.elements.counted - var j = that.elements + def indexOf[B >: A](that : Seq[B]) : Int = { + val i = this.elements var idx = 0 + var j = that.elements + var jdx = -1 while (i.hasNext && j.hasNext) { + idx = idx + 1 if (i.next != j.next) { j = that.elements - idx = -1 - } else if (idx == -1) { - idx = i.count - 1 + jdx = -1 + } else if (jdx == -1) { + jdx = idx - 1 } } - idx + jdx } /** Is <code>that</code> a slice in this? */ |