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

Unified Diff: pkg/compiler/lib/src/closure.dart

Issue 802813004: Avoid boxing loop variables that are only mutated in initializer or update (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/closure.dart
diff --git a/pkg/compiler/lib/src/closure.dart b/pkg/compiler/lib/src/closure.dart
index 4ba9b212aa9b0c21753678899bb065c3dec11058..46219a33ac29ccc264bde6431b51024c7609aa6c 100644
--- a/pkg/compiler/lib/src/closure.dart
+++ b/pkg/compiler/lib/src/closure.dart
@@ -818,7 +818,30 @@ class ClosureTranslator extends Visitor {
}
visitFor(For node) {
- visitLoop(node);
+ inNewScope(node, () {
+ // First visit initializer and update so we can easily check if a loop
+ // variable was captured in one of these subexpressions.
+ if (node.initializer != null) visit(node.initializer);
+ if (node.update != null) visit(node.update);
+
+ // Loop variables that have not been captured yet can safely be flagged as
+ // non-mutated, because no nested function can observe the mutation.
+ if (node.initializer is VariableDefinitions) {
+ VariableDefinitions definitions = node.initializer;
+ definitions.definitions.nodes.forEach((Node node) {
+ LocalVariableElement local = elements[node];
+ if (!isCapturedVariable(local)) {
+ mutatedVariables.remove(local);
+ }
+ });
+ }
+
+ // Visit condition and body.
+ // This must happen after the above, so any loop variables mutated in the
+ // condition or body are indeed flagged as mutated.
+ if (node.conditionStatement != null) visit(node.conditionStatement);
+ if (node.body != null) visit(node.body);
+ });
// See if we have declared loop variables that need to be boxed.
if (node.initializer == null) return;
VariableDefinitions definitions = node.initializer.asVariableDefinitions();
« no previous file with comments | « no previous file | tests/compiler/dart2js/forloop_box_test.dart » ('j') | tests/compiler/dart2js/forloop_box_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698