From 2facac90e8c3cae5cbe29a55835c69847d270a40 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Wed, 2 Apr 2008 14:11:46 +0000 Subject: Changed Stream implementation to use tail recur... Changed Stream implementation to use tail recursive calls directly, instead of tail-recursive local functions. This has better GC behavior, see ticket #692. --- test/files/run/streams.check | 6 ++++++ test/files/run/streams.scala | 14 ++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'test/files') diff --git a/test/files/run/streams.check b/test/files/run/streams.check index 5346c73d12..7f894052d9 100644 --- a/test/files/run/streams.check +++ b/test/files/run/streams.check @@ -17,3 +17,9 @@ Stream() 999 512 +100000 +Stream(100001, ?) +Stream(100001, ?) +true +true +705082704 diff --git a/test/files/run/streams.scala b/test/files/run/streams.scala index 1e781a6171..970f3cef16 100644 --- a/test/files/run/streams.scala +++ b/test/files/run/streams.scala @@ -29,4 +29,18 @@ object Test extends Application { def powers(x: Int) = if ((x&(x-1)) == 0) Some(x) else None println(s3.flatMap(powers).reverse.head) + // large enough to generate StackOverflows (on most systems) + // unless the following methods are tail call optimized. + val size = 100000 + + // test tail recursive methods + println(Stream.from(1).take(size).last) + println(Stream.from(1).drop(size)) + println(Stream.from(1).filter(_ > size).take(5)) + println(Stream.from(1).take(size).forall(_ >= 0)) + println(Stream.from(1).exists(_ > size)) + Stream.from(1).take(size).foreach( x => () ) + println(Stream.from(1).take(size).foldLeft(0)(_ + _)) + val arr = new Array[Int](size) + Stream.from(1).take(size).copyToArray(arr, 0) } -- cgit v1.2.3