Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1405023004: dart2js cps: Prefer unlabeled continue over labeled break. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 d9f24032c5476e39a485df88927df8c4955b5a95..d27c1f05567610c3023cbbe959ef2d57d305b682 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
@@ -471,6 +471,13 @@ class CodeGenerator extends tree_ir.StatementVisitor
other is tree_ir.Break && node.target == other.target;
}
+ /// True if the given break is equivalent to an unlabeled continue.
+ bool isShortContinue(tree_ir.Break node) {
+ tree_ir.Statement next = node.target.binding.next;
+ return next is tree_ir.Continue &&
+ next.target.binding == shortContinue.target;
+ }
+
@override
void visitBreak(tree_ir.Break node) {
if (isEffectiveBreakTarget(node, fallthrough.target)) {
@@ -480,6 +487,10 @@ class CodeGenerator extends tree_ir.StatementVisitor
// Unlabeled break to the break target or to an equivalent break.
shortBreak.use();
accumulator.add(new js.Break(null));
+ } else if (isShortContinue(node)) {
+ // An unlabeled continue is better than a labeled break.
+ shortContinue.use();
+ accumulator.add(new js.Continue(null));
} else {
usedLabels.add(node.target);
accumulator.add(new js.Break(node.target.name));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698