diff options
author | Lex Spoon <lex@lexspoon.org> | 2007-10-04 07:44:01 +0000 |
---|---|---|
committer | Lex Spoon <lex@lexspoon.org> | 2007-10-04 07:44:01 +0000 |
commit | 49592a353d8e4f962c3c7c31423a62e15a7c0fad (patch) | |
tree | 14f24d3e4c4a43218e7ac66f1553e57f885371e3 | |
parent | 08704a195e925dbf82f268f44fb1283b4ffe8062 (diff) | |
download | scala-49592a353d8e4f962c3c7c31423a62e15a7c0fad.tar.gz scala-49592a353d8e4f962c3c7c31423a62e15a7c0fad.tar.bz2 scala-49592a353d8e4f962c3c7c31423a62e15a7c0fad.zip |
made Stream.length not be recursive
-rw-r--r-- | src/library/scala/Stream.scala | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/library/scala/Stream.scala b/src/library/scala/Stream.scala index 51c96b3f0c..5a4a705a61 100644 --- a/src/library/scala/Stream.scala +++ b/src/library/scala/Stream.scala @@ -195,7 +195,15 @@ trait Stream[+A] extends Seq.Projection[A] { def tail: Stream[A] /** The length of this stream */ - override def length: Int = if (isEmpty) 0 else tail.length + 1 + override def length: Int = { + var len = 0 + var here = this + while (!here.isEmpty) { + len += 1 + here = here.tail + } + len + } /** returns length - l without calling length */ |