diff options
author | James Iry <jamesiry@gmail.com> | 2013-01-30 15:29:42 -0800 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-01-31 14:16:59 -0800 |
commit | 6db4db93a7d976f1a3b99f8f1bffff23a1ae3924 (patch) | |
tree | 1a4ee752d56913426f76fbcee657480af57af0c5 /src/library | |
parent | 7026376dcc87f531de84c99aa3e52068f5b10874 (diff) | |
download | scala-6db4db93a7d976f1a3b99f8f1bffff23a1ae3924.tar.gz scala-6db4db93a7d976f1a3b99f8f1bffff23a1ae3924.tar.bz2 scala-6db4db93a7d976f1a3b99f8f1bffff23a1ae3924.zip |
SI-2818 Make List.foldRight always do a reverse/foldLeft flip
Benchmarks show that lists smaller than 110 elements or so doing
reverse/foldLeft is faster than recursively walking to the end of
the list and then folding as the stack unwinds.
Above that 110 element threshold the recursive procedure is faster.
Unfortunately, at some magic unknown large size the recursive procedure
blows the stack.
This commit changes List#foldRight to always do reverse/foldLeft.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/immutable/List.scala | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index 56e386ad67..55ac3995e9 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -295,6 +295,9 @@ sealed abstract class List[+A] extends AbstractSeq[A] } result } + + override def foldRight[B](z: B)(op: (A, B) => B): B = + reverse.foldLeft(z)((right, left) => op(left, right)) override def stringPrefix = "List" |