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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1584693003: dart2js cps: for(;;) is shorter than while(true) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | tests/compiler/dart2js/cps_ir/expected/control_flow_1.js » ('j') | 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 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 } 742 }
743 js.Expression update = makeSequence(node.updates); 743 js.Expression update = makeSequence(node.updates);
744 loopNode = new js.For(init, condition, update, body); 744 loopNode = new js.For(init, condition, update, body);
745 } 745 }
746 accumulator.add(insertLabel(node.label, loopNode)); 746 accumulator.add(insertLabel(node.label, loopNode));
747 visitStatement(node.next); 747 visitStatement(node.next);
748 } 748 }
749 749
750 @override 750 @override
751 void visitWhileTrue(tree_ir.WhileTrue node) { 751 void visitWhileTrue(tree_ir.WhileTrue node) {
752 js.Expression condition = new js.LiteralBool(true);
753 // A short break in the while will jump to the current fallthrough target. 752 // A short break in the while will jump to the current fallthrough target.
754 shortBreak.push(fallthrough.target); 753 shortBreak.push(fallthrough.target);
755 shortContinue.push(node); 754 shortContinue.push(node);
756 fallthrough.push(node); 755 fallthrough.push(node);
757 emitUnreachableAsReturn.add(true); 756 emitUnreachableAsReturn.add(true);
758 js.Statement jsBody = buildBodyStatement(node.body); 757 js.Statement jsBody = buildBodyStatement(node.body);
759 emitUnreachableAsReturn.removeLast(); 758 emitUnreachableAsReturn.removeLast();
760 fallthrough.pop(); 759 fallthrough.pop();
761 shortContinue.pop(); 760 shortContinue.pop();
762 if (shortBreak.useCount > 0) { 761 if (shortBreak.useCount > 0) {
763 // Short breaks use the current fallthrough target. 762 // Short breaks use the current fallthrough target.
764 fallthrough.use(); 763 fallthrough.use();
765 } 764 }
766 shortBreak.pop(); 765 shortBreak.pop();
767 accumulator.add(insertLabel(node.label, new js.While(condition, jsBody))); 766 accumulator.add(
767 insertLabel(node.label, new js.For(null, null, null, jsBody)));
768 } 768 }
769 769
770 bool isNull(tree_ir.Expression node) { 770 bool isNull(tree_ir.Expression node) {
771 return node is tree_ir.Constant && node.value.isNull; 771 return node is tree_ir.Constant && node.value.isNull;
772 } 772 }
773 773
774 @override 774 @override
775 void visitReturn(tree_ir.Return node) { 775 void visitReturn(tree_ir.Return node) {
776 if (isNull(node.value) && fallthrough.target == null) { 776 if (isNull(node.value) && fallthrough.target == null) {
777 // Do nothing. Implicitly return JS undefined by falling over the end. 777 // Do nothing. Implicitly return JS undefined by falling over the end.
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 void registerDefaultParameterValues(ExecutableElement element) { 1225 void registerDefaultParameterValues(ExecutableElement element) {
1226 if (element is! FunctionElement) return; 1226 if (element is! FunctionElement) return;
1227 FunctionElement function = element; 1227 FunctionElement function = element;
1228 if (function.isStatic) return; // Defaults are inlined at call sites. 1228 if (function.isStatic) return; // Defaults are inlined at call sites.
1229 function.functionSignature.forEachOptionalParameter((param) { 1229 function.functionSignature.forEachOptionalParameter((param) {
1230 ConstantValue constant = glue.getDefaultParameterValue(param); 1230 ConstantValue constant = glue.getDefaultParameterValue(param);
1231 registry.registerCompileTimeConstant(constant); 1231 registry.registerCompileTimeConstant(constant);
1232 }); 1232 });
1233 } 1233 }
1234 } 1234 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/cps_ir/expected/control_flow_1.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698