summaryrefslogtreecommitdiff
path: root/test/files
diff options
context:
space:
mode:
authorRex Kerr <ichoran@gmail.com>2014-02-10 02:17:27 -0800
committerRex Kerr <ichoran@gmail.com>2014-02-25 05:39:13 -0800
commitc5962b1871f8093fe200fe0c47cd9c202b07a8f9 (patch)
tree8ca06a81c39c11c44f10dabd23499b63506dbda7 /test/files
parent1ea43ffb2286d63e133839c1ea0b09449b0ac168 (diff)
downloadscala-c5962b1871f8093fe200fe0c47cd9c202b07a8f9.tar.gz
scala-c5962b1871f8093fe200fe0c47cd9c202b07a8f9.tar.bz2
scala-c5962b1871f8093fe200fe0c47cd9c202b07a8f9.zip
SI-8240 Consider rolling back optimizations for List
Some compiler-specific optimizations turn out to be very helpful for Lists in general. * List map can be a lot faster (up to 5x!) * List collect can be considerably faster (up to 3x) * List flatMap can be a bit faster (2x) * List take can be slightly faster (1.1x) and have better structural sharing These appear to be unqualified wins (tested), even in a scenario with mixed collections. This is expected: detecting the builder is faster than the otherwise mandatory object creation, and multiple dispatch is mostly a wash since it was already multiple dispatch in getting to the builder. With -optimize, map is not always such a big win, but is never slower. Also added @noinline to map to work around an optimizer bug (SI-8334) and added a test to check that the pattern that triggers the optimizer bug does not affect any of the map-like methods.
Diffstat (limited to 'test/files')
-rw-r--r--test/files/pos/list-optim-check.flags1
-rw-r--r--test/files/pos/list-optim-check.scala21
2 files changed, 22 insertions, 0 deletions
diff --git a/test/files/pos/list-optim-check.flags b/test/files/pos/list-optim-check.flags
new file mode 100644
index 0000000000..49d036a887
--- /dev/null
+++ b/test/files/pos/list-optim-check.flags
@@ -0,0 +1 @@
+-optimize
diff --git a/test/files/pos/list-optim-check.scala b/test/files/pos/list-optim-check.scala
new file mode 100644
index 0000000000..f6e6ddec77
--- /dev/null
+++ b/test/files/pos/list-optim-check.scala
@@ -0,0 +1,21 @@
+// Tests a map known to crash in optimizer with faster List map in SI-8240.
+// Equivalent tests for collect and flatmap do not crash, but are provided
+// anyway.
+// See ticket SI-8334 for optimizer bug.
+// TODO - Remove this test once SI-8334 is fixed and has its own test.
+class A {
+ def f: Boolean = {
+ val xs = Nil map (_ => return false)
+ true
+ }
+
+ def g: Boolean = {
+ val xs = Nil collect { case _ => return false }
+ true
+ }
+
+ def h: Boolean = {
+ val xs = Nil flatMap { _ => return false }
+ true
+ }
+}