From eadb59e4c191731444926888cbfa2172bb0984ed Mon Sep 17 00:00:00 2001 From: Asger Feldthaus Date: Wed, 6 Jan 2016 16:18:00 -0800 Subject: [PATCH] dart2js cps: Eliminate unary string concatenation. BUG= R=kmillikin@google.com Review URL: https://codereview.chromium.org/1563983002 . --- pkg/compiler/lib/src/cps_ir/type_propagation.dart | 5 +++++ tests/compiler/dart2js/js_backend_cps_ir_operators_test.dart | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/compiler/lib/src/cps_ir/type_propagation.dart b/pkg/compiler/lib/src/cps_ir/type_propagation.dart index d20178c4404..bf5658abbf7 100644 --- a/pkg/compiler/lib/src/cps_ir/type_propagation.dart +++ b/pkg/compiler/lib/src/cps_ir/type_propagation.dart @@ -2073,6 +2073,11 @@ class TransformingVisitor extends DeepRecursiveVisitor { if (argumentsWereRemoved) { node.arguments.removeWhere((ref) => ref == null); } + if (node.arguments.length == 1) { + Primitive input = node.arguments[0].definition; + node.replaceUsesWith(input); + input.useElementAsHint(node.hint); + } // TODO(asgerf): Rebalance nested StringConcats that arise from // rewriting the + operator to StringConcat. break; diff --git a/tests/compiler/dart2js/js_backend_cps_ir_operators_test.dart b/tests/compiler/dart2js/js_backend_cps_ir_operators_test.dart index 152a552a0a4..08914caeaa0 100644 --- a/tests/compiler/dart2js/js_backend_cps_ir_operators_test.dart +++ b/tests/compiler/dart2js/js_backend_cps_ir_operators_test.dart @@ -130,11 +130,10 @@ main() { print(list); }""", r""" function() { - var list = [1, 2, 3], res, v0; + var list = [1, 2, 3], v0; list[1] = 6; - if (!(typeof (res = C.JSArray_methods.toString$0(list)) === "string")) + if (!(typeof (v0 = P.IterableBase_iterableToFullString(list, "[", "]")) === "string")) throw H.wrapException(H.argumentErrorValue(list)); - v0 = res; if (typeof dartPrint == "function") dartPrint(v0); else if (typeof console == "object" && typeof console.log != "undefined")