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:
parent
0ff3259ac9
commit
0976df4fa6
|
@ -195,7 +195,15 @@ trait Stream[+A] extends Seq.Projection[A] {
|
||||||
def tail: Stream[A]
|
def tail: Stream[A]
|
||||||
|
|
||||||
/** The length of this stream */
|
/** 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
|
/** returns length - l without calling length
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue