Chromium Code Reviews| Index: lib/compiler/implementation/ssa/optimize.dart |
| diff --git a/lib/compiler/implementation/ssa/optimize.dart b/lib/compiler/implementation/ssa/optimize.dart |
| index d29e599fd5bb3738e8498a0bd61ffd9c05405196..36c29cee48b56bd7ed7c7d46c6f2146755d5305c 100644 |
| --- a/lib/compiler/implementation/ssa/optimize.dart |
| +++ b/lib/compiler/implementation/ssa/optimize.dart |
| @@ -590,6 +590,28 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase { |
| if (field === null) return node; |
| return new HFieldSet(field, node.inputs[0], node.inputs[1]); |
| } |
| + |
| + bool isEmptyString(HInstruction node) { |
| + if (!node.isConstantString()) return false; |
| + HConstant constant = node; |
| + StringConstant string = constant.constant; |
| + return string.value.length == 0; |
| + } |
| + |
| + HInstruction visitStringConcat(HStringConcat node) { |
| + if (isEmptyString(node.inputs[0])) return node.inputs[1]; |
| + if (isEmptyString(node.inputs[1])) return node.inputs[0]; |
| + DartString folded = const LiteralDartString(""); |
| + for (int i = 0; i < node.inputs.length; i++) { |
|
Lasse Reichstein Nielsen
2012/06/06 12:11:40
This seems to assume more than two inputs. Intenti
|
| + HInstruction part = node.inputs[i]; |
| + if (!part.isConstant()) return node; |
| + HConstant constant = part; |
| + if (!constant.constant.isPrimitive()) return node; |
| + PrimitiveConstant primitive = constant.constant; |
| + folded = new DartString.concat(folded, primitive.toDartString()); |
| + } |
| + return graph.addConstantString(folded, node); |
| + } |
| } |
| class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase { |