summaryrefslogtreecommitdiff
path: root/test/files/run/concat-two-strings.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-15 23:21:25 +0000
committerPaul Phillips <paulp@improving.org>2011-01-15 23:21:25 +0000
commit866801385f81417a2ac33916280df918e4bd5b3b (patch)
tree17cf474ab89a37804af270c97852d580a576beec /test/files/run/concat-two-strings.scala
parent604797b64518cbd75583e6ac14876552d6598c9d (diff)
downloadscala-866801385f81417a2ac33916280df918e4bd5b3b.tar.gz
scala-866801385f81417a2ac33916280df918e4bd5b3b.tar.bz2
scala-866801385f81417a2ac33916280df918e4bd5b3b.zip
Optimization to string concatenation.
with a primitive CONCAT and several opcodes, I'm assuming nobody will oppose this on principle. Given an expression of the exact form "" + x (that is, the NPE-immune and much less ugly way to call .toString) we used to get 4x the bytecode and create an unneeded StringBuilder. Now this: 0: aload_1 1: invokestatic #20; //Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String; 4: areturn Closes #4160, review by dragos.
Diffstat (limited to 'test/files/run/concat-two-strings.scala')
-rw-r--r--test/files/run/concat-two-strings.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/test/files/run/concat-two-strings.scala b/test/files/run/concat-two-strings.scala
new file mode 100644
index 0000000000..c8881aa146
--- /dev/null
+++ b/test/files/run/concat-two-strings.scala
@@ -0,0 +1,15 @@
+/** This doesn't test that the optimization is working, only that
+ * nothing is exploding.
+ */
+object Test {
+ def f1(x: AnyRef) = "" + x
+ def f2(x: Int) = "" + x
+ def f3(x: Array[Char]) = "" + x
+ def f4(x: List[Int]) = "" + x
+ def f5(x: Any) = "" + x
+ def f6(x: AnyVal) = "" + x
+
+ def main(args: Array[String]): Unit = {
+ List(f1("a"), f2(5), f3(null), f3(Array('a')), f4(List(1)), f5(null), f6(55d)) mkString ""
+ }
+}