made Stream.length not be recursive

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@12994 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
spoon 2007-10-04 07:44:01 +00:00
parent 0ff3259ac9
commit 0976df4fa6
1 changed files with 9 additions and 1 deletions

View File

@ -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
*/