Chromium Code Reviews| Index: pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
| diff --git a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
| index 0da171bc16c40dc5937612a6ae902d981a5a06f6..4c74feffb64d48af2d8d5c7a29974e966687eb9d 100644 |
| --- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
| +++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart |
| @@ -81,7 +81,7 @@ class CodeGenerator extends tree_ir.StatementVisitor |
| /// [Unreachable] statements whether they may use fallthrough or not. |
| List<bool> emitUnreachableAsReturn = <bool>[false]; |
| - Set<tree_ir.Label> usedLabels = new Set<tree_ir.Label>(); |
| + final Map<tree_ir.Label, String> labelNames = <tree_ir.Label, String>{}; |
| List<js.Statement> accumulator = new List<js.Statement>(); |
| @@ -581,8 +581,7 @@ class CodeGenerator extends tree_ir.StatementVisitor |
| shortContinue.use(); |
| accumulator.add(new js.Continue(null)); |
| } else { |
| - usedLabels.add(node.target); |
| - accumulator.add(new js.Continue(node.target.name)); |
| + accumulator.add(new js.Continue(makeLabel(node.target))); |
| } |
| } |
| @@ -614,8 +613,7 @@ class CodeGenerator extends tree_ir.StatementVisitor |
| shortContinue.use(); |
| accumulator.add(new js.Continue(null)); |
| } else { |
| - usedLabels.add(node.target); |
| - accumulator.add(new js.Break(node.target.name)); |
| + accumulator.add(new js.Break(makeLabel(node.target))); |
| } |
| } |
| @@ -670,13 +668,21 @@ class CodeGenerator extends tree_ir.StatementVisitor |
| visitStatement(node.next); |
| } |
| + /// Creates a name for [label] if it does not already have one. |
| + /// |
| + /// This also marks the label as being used. |
| + String makeLabel(tree_ir.Label label) { |
| + String name = labelNames[label]; |
|
Kevin Millikin (Google)
2016/01/08 22:05:47
You could use putIfAbsent here.
asgerf
2016/01/08 22:13:29
Done.
|
| + if (name != null) return name; |
| + int count = labelNames.length; |
| + return labelNames[label] = 'L$count'; |
| + } |
| + |
| /// Wraps a node in a labeled statement unless the label is unused. |
| js.Statement insertLabel(tree_ir.Label label, js.Statement node) { |
| - if (usedLabels.remove(label)) { |
| - return new js.LabeledStatement(label.name, node); |
| - } else { |
| - return node; |
| - } |
| + String name = labelNames[label]; |
| + if (name == null) return node; // Label is unused. |
| + return new js.LabeledStatement(name, node); |
| } |
| /// Returns the current [accumulator] wrapped in a block if neccessary. |