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

Unified Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 10962015: Rewrite blocks of single operator into just a single operator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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: lib/compiler/implementation/dart_backend/backend.dart
diff --git a/lib/compiler/implementation/dart_backend/backend.dart b/lib/compiler/implementation/dart_backend/backend.dart
index 0f9ec2b54a12308d9798526044d4b42cdb481b2d..e9af56a075b73bd0ec0d47a1505afc6f1a297342 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -82,13 +82,28 @@ class FunctionBodyRewriter extends CloningVisitor {
return false;
}
+ rewritTo(Statement statement) {
Roman 2012/09/21 12:10:27 tryRewriteSingleStatementBlock?
Anton Muhin 2012/09/21 12:13:08 There should be no references to single statement
Roman 2012/09/21 12:16:00 then just rewriteStatement? side note: does 'try'
+ if (statement is Block) {
+ Link statements = statement.statements.nodes;
+ if (!statements.isEmpty() && statements.tail.isEmpty()) {
+ Statement single = statements.head;
+ bool isDeclaration =
+ single is VariableDefinitions || single is FunctionDeclaration;
+ if (!isDeclaration) return single;
+ }
+ }
+ return statement;
+ }
+
rewriteBody(Statement body) {
if (body is !Block) return visit(body);
Block block = body;
NodeList statements = block.statements;
LinkBuilder<Statement> builder = new LinkBuilder<Statement>();
for (Statement statement in statements.nodes) {
- if (!shouldOmit(statement)) builder.addLast(visit(statement));
+ if (!shouldOmit(statement)) {
+ builder.addLast(visit(rewritTo(statement)));
+ }
}
return new Block(rewriteNodeList(statements, builder.toLink()));
}
« 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