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

Side by Side 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: Rebase 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/compiler/dart2js/forloop_box_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library closureToClassMapper; 5 library closureToClassMapper;
6 6
7 import "elements/elements.dart"; 7 import "elements/elements.dart";
8 import "dart2jslib.dart"; 8 import "dart2jslib.dart";
9 import "dart_types.dart"; 9 import "dart_types.dart";
10 import "js_backend/js_backend.dart" show JavaScriptBackend; 10 import "js_backend/js_backend.dart" show JavaScriptBackend;
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 scopeVariables = oldScopeVariables; 811 scopeVariables = oldScopeVariables;
812 } 812 }
813 813
814 visitLoop(Loop node) { 814 visitLoop(Loop node) {
815 inNewScope(node, () { 815 inNewScope(node, () {
816 node.visitChildren(this); 816 node.visitChildren(this);
817 }); 817 });
818 } 818 }
819 819
820 visitFor(For node) { 820 visitFor(For node) {
821 visitLoop(node); 821 inNewScope(node, () {
822 // First visit initializer and update so we can easily check if a loop
823 // variable was captured in one of these subexpressions.
824 if (node.initializer != null) visit(node.initializer);
825 if (node.update != null) visit(node.update);
826
827 // Loop variables that have not been captured yet can safely be flagged as
828 // non-mutated, because no nested function can observe the mutation.
829 if (node.initializer is VariableDefinitions) {
830 VariableDefinitions definitions = node.initializer;
831 definitions.definitions.nodes.forEach((Node node) {
832 LocalVariableElement local = elements[node];
833 if (!isCapturedVariable(local)) {
834 mutatedVariables.remove(local);
835 }
836 });
837 }
838
839 // Visit condition and body.
840 // This must happen after the above, so any loop variables mutated in the
841 // condition or body are indeed flagged as mutated.
842 if (node.conditionStatement != null) visit(node.conditionStatement);
843 if (node.body != null) visit(node.body);
844 });
822 // See if we have declared loop variables that need to be boxed. 845 // See if we have declared loop variables that need to be boxed.
823 if (node.initializer == null) return; 846 if (node.initializer == null) return;
824 VariableDefinitions definitions = node.initializer.asVariableDefinitions(); 847 VariableDefinitions definitions = node.initializer.asVariableDefinitions();
825 if (definitions == null) return; 848 if (definitions == null) return;
826 ClosureScope scopeData = closureData.capturingScopes[node]; 849 ClosureScope scopeData = closureData.capturingScopes[node];
827 if (scopeData == null) return; 850 if (scopeData == null) return;
828 List<LocalVariableElement> result = <LocalVariableElement>[]; 851 List<LocalVariableElement> result = <LocalVariableElement>[];
829 for (Link<Node> link = definitions.definitions.nodes; 852 for (Link<Node> link = definitions.definitions.nodes;
830 !link.isEmpty; 853 !link.isEmpty;
831 link = link.tail) { 854 link = link.tail) {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 1015
993 String get name => typeVariable.name; 1016 String get name => typeVariable.name;
994 1017
995 int get hashCode => typeVariable.hashCode; 1018 int get hashCode => typeVariable.hashCode;
996 1019
997 bool operator ==(other) { 1020 bool operator ==(other) {
998 if (other is! TypeVariableLocal) return false; 1021 if (other is! TypeVariableLocal) return false;
999 return typeVariable == other.typeVariable; 1022 return typeVariable == other.typeVariable;
1000 } 1023 }
1001 } 1024 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/forloop_box_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698