From 696fb20ecee89db92fd801eb7fd321bf60910339 Mon Sep 17 00:00:00 2001 From: "ager@google.com" Date: Fri, 1 Jun 2012 13:15:19 +0000 Subject: [PATCH] Avoid repeated declaration of the same loop variable. The following code: void main() { int j = 0; for (int i = 0; i < 10; i++) { j++; } } would generate the following: for (var j = 0, i = 0; i < 10; ) { j = j + 1; var i = i + 1; } with this change the 'var' in the body disappears. R=ngeoffray@google.com BUG= TEST= Review URL: https://chromiumcodereview.appspot.com//10471002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@8192 260f80e4-7a28-3924-810f-c04153c831b5 --- lib/compiler/compiler.dart | 4 +--- lib/compiler/implementation/dart2js.dart | 4 +--- lib/compiler/implementation/ssa/codegen.dart | 9 ++++++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/compiler/compiler.dart b/lib/compiler/compiler.dart index b7a780fe826..4038fad3606 100644 --- a/lib/compiler/compiler.dart +++ b/lib/compiler/compiler.dart @@ -46,7 +46,5 @@ Future compile(Uri script, options); compiler.run(script); String code = compiler.assembledCode; - Completer completer = new Completer(); - completer.complete(code); - return completer.future; + return new Future.immediate(code); } diff --git a/lib/compiler/implementation/dart2js.dart b/lib/compiler/implementation/dart2js.dart index 1593ca608a4..e463a62ec3b 100644 --- a/lib/compiler/implementation/dart2js.dart +++ b/lib/compiler/implementation/dart2js.dart @@ -164,9 +164,7 @@ void compile(List argv) { dartBytesRead += source.length; sourceFiles[uri.toString()] = new SourceFile(relativize(cwd, uri), source); - Completer completer = new Completer(); - completer.complete(source); - return completer.future; + return new Future.immediate(source); } void info(var message) { diff --git a/lib/compiler/implementation/ssa/codegen.dart b/lib/compiler/implementation/ssa/codegen.dart index 44664d94087..6465ac096f6 100644 --- a/lib/compiler/implementation/ssa/codegen.dart +++ b/lib/compiler/implementation/ssa/codegen.dart @@ -468,9 +468,12 @@ class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { declaredVariables.add(variableName); buffer.add("var "); } - } else if (!isGeneratingDeclaration() - && !isVariableDeclared(variableName)) { - delayedVariablesDeclaration.add(variableName); + } else if (!isVariableDeclared(variableName)) { + if (!isGeneratingDeclaration()) { + delayedVariablesDeclaration.add(variableName); + } else { + declaredVariables.add(variableName); + } } } else if (!isVariableDeclared(variableName)) { declaredVariables.add(variableName);