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

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

Issue 2810093002: Don't duplicate switch case code if we fall through to the default case. (Closed)
Patch Set: Created 3 years, 8 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 | tests/compiler/dart2js_extra/switch_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/codegen.dart
diff --git a/pkg/compiler/lib/src/ssa/codegen.dart b/pkg/compiler/lib/src/ssa/codegen.dart
index 9eda4542b891ce7a220c258840d1ac9477b5b694..0fdd9794d3f2de11abd65b37d1e7722872d783f5 100644
--- a/pkg/compiler/lib/src/ssa/codegen.dart
+++ b/pkg/compiler/lib/src/ssa/codegen.dart
@@ -765,6 +765,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
use(info.expression.conditionExpression);
}
js.Expression key = pop();
+ bool handledDefault = false;
List<js.SwitchClause> cases = <js.SwitchClause>[];
HSwitch switchInstruction = info.expression.end.last;
List<HInstruction> inputs = switchInstruction.inputs;
@@ -786,6 +787,14 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
} while ((successors[inputIndex - 1] == successor) &&
(inputIndex < inputs.length));
+ // If this is the last statement, then these cases also belong to the
+ // default block.
+ if (statementIndex == info.statements.length - 1) {
+ currentContainer = new js.Block.empty();
+ cases.add(new js.Default(currentContainer));
+ handledDefault = true;
+ }
+
generateStatements(info.statements[statementIndex]);
} else {
// Skip all the case statements that belong to this
@@ -799,7 +808,7 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor {
// If the default case is dead, we omit it. Likewise, if it is an
// empty block, we omit it, too.
- if (info.statements.last.start.isLive) {
+ if (info.statements.last.start.isLive && !handledDefault) {
currentContainer = new js.Block.empty();
generateStatements(info.statements.last);
if (currentContainer.statements.isNotEmpty) {
« no previous file with comments | « no previous file | tests/compiler/dart2js_extra/switch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698