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

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..45447087a6899a7a8ed0149806268d089b0dcb52 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -82,13 +82,26 @@ class FunctionBodyRewriter extends CloningVisitor {
return false;
}
+ rewritTo(Statement statement) {
Roman 2012/09/21 08:10:37 rewriteTo? "rewriteTo" is a weird name. What does
Anton Muhin 2012/09/21 12:02:14 Any better proposals?
+ if (statement is Block) {
+ Link statements = statement.statements.nodes;
+ if (!statements.isEmpty() && statements.tail.isEmpty()) {
+ Statement single = statements.head;
+ if (single is !VariableDefinitions) return single;
Roman 2012/09/21 08:10:37 What about function declarations? main() { f(){
Anton Muhin 2012/09/21 12:02:14 Well spotted, thanks a lot! On 2012/09/21 08:10:3
+ }
+ }
+ 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