summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2008-04-02 14:11:46 +0000
committerIulian Dragos <jaguarul@gmail.com>2008-04-02 14:11:46 +0000
commit2facac90e8c3cae5cbe29a55835c69847d270a40 (patch)
tree37fd17257109a8fef3ece98f2fcb9d1e3bf8d78b /test/files
parent66515781fa9823e200779e5d53aa244e46e22f02 (diff)
downloadscala-2facac90e8c3cae5cbe29a55835c69847d270a40.tar.gz
scala-2facac90e8c3cae5cbe29a55835c69847d270a40.tar.bz2
scala-2facac90e8c3cae5cbe29a55835c69847d270a40.zip
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.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/run/streams.check6
-rw-r--r--test/files/run/streams.scala14
2 files changed, 20 insertions, 0 deletions
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)
}