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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../closure.dart' show 9 import '../../closure.dart' show
10 ClosureClassElement; 10 ClosureClassElement;
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 464 }
465 } 465 }
466 466
467 /// True if [other] is the target of [node] or is a [Break] with the same 467 /// True if [other] is the target of [node] or is a [Break] with the same
468 /// target. This means jumping to [other] is equivalent to executing [node]. 468 /// target. This means jumping to [other] is equivalent to executing [node].
469 bool isEffectiveBreakTarget(tree_ir.Break node, tree_ir.Statement other) { 469 bool isEffectiveBreakTarget(tree_ir.Break node, tree_ir.Statement other) {
470 return node.target.binding.next == other || 470 return node.target.binding.next == other ||
471 other is tree_ir.Break && node.target == other.target; 471 other is tree_ir.Break && node.target == other.target;
472 } 472 }
473 473
474 /// True if the given break is equivalent to an unlabeled continue.
475 bool isShortContinue(tree_ir.Break node) {
476 tree_ir.Statement next = node.target.binding.next;
477 return next is tree_ir.Continue &&
478 next.target.binding == shortContinue.target;
479 }
480
474 @override 481 @override
475 void visitBreak(tree_ir.Break node) { 482 void visitBreak(tree_ir.Break node) {
476 if (isEffectiveBreakTarget(node, fallthrough.target)) { 483 if (isEffectiveBreakTarget(node, fallthrough.target)) {
477 // Fall through to break target or to equivalent break. 484 // Fall through to break target or to equivalent break.
478 fallthrough.use(); 485 fallthrough.use();
479 } else if (isEffectiveBreakTarget(node, shortBreak.target)) { 486 } else if (isEffectiveBreakTarget(node, shortBreak.target)) {
480 // Unlabeled break to the break target or to an equivalent break. 487 // Unlabeled break to the break target or to an equivalent break.
481 shortBreak.use(); 488 shortBreak.use();
482 accumulator.add(new js.Break(null)); 489 accumulator.add(new js.Break(null));
490 } else if (isShortContinue(node)) {
491 // An unlabeled continue is better than a labeled break.
492 shortContinue.use();
493 accumulator.add(new js.Continue(null));
483 } else { 494 } else {
484 usedLabels.add(node.target); 495 usedLabels.add(node.target);
485 accumulator.add(new js.Break(node.target.name)); 496 accumulator.add(new js.Break(node.target.name));
486 } 497 }
487 } 498 }
488 499
489 @override 500 @override
490 void visitExpressionStatement(tree_ir.ExpressionStatement node) { 501 void visitExpressionStatement(tree_ir.ExpressionStatement node) {
491 accumulator.add(new js.ExpressionStatement( 502 accumulator.add(new js.ExpressionStatement(
492 visitExpression(node.expression))); 503 visitExpression(node.expression)));
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 void registerDefaultParameterValues(ExecutableElement element) { 1041 void registerDefaultParameterValues(ExecutableElement element) {
1031 if (element is! FunctionElement) return; 1042 if (element is! FunctionElement) return;
1032 FunctionElement function = element; 1043 FunctionElement function = element;
1033 if (function.isStatic) return; // Defaults are inlined at call sites. 1044 if (function.isStatic) return; // Defaults are inlined at call sites.
1034 function.functionSignature.forEachOptionalParameter((param) { 1045 function.functionSignature.forEachOptionalParameter((param) {
1035 ConstantValue constant = glue.getDefaultParameterValue(param); 1046 ConstantValue constant = glue.getDefaultParameterValue(param);
1036 registry.registerCompileTimeConstant(constant); 1047 registry.registerCompileTimeConstant(constant);
1037 }); 1048 });
1038 } 1049 }
1039 } 1050 }
OLDNEW
« 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