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

Unified Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 830463003: dart2js: collect static-non-final fields in the task. (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
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/code_emitter_task.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
index e2b02f17046c3f83f0114b26d6da0ff73970ec38..3bb7c04256f8c75954122ade8eaf8fd6f129f9cf 100644
--- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
@@ -767,33 +767,43 @@ class OldEmitter implements Emitter {
void emitStaticNonFinalFieldInitializations(CodeBuffer buffer,
OutputUnit outputUnit) {
+ void emitInitialization(Element element, jsAst.Expression initialValue) {
+ jsAst.Expression init =
+ js('$isolateProperties.# = #',
+ [namer.getNameOfGlobalField(element), initialValue]);
+ buffer.write(jsAst.prettyPrint(init, compiler,
+ monitor: compiler.dumpInfoTask));
+ buffer.write('$N');
+ }
+
+ bool inMainUnit = (outputUnit == compiler.deferredLoadTask.mainOutputUnit);
JavaScriptConstantCompiler handler = backend.constants;
- Iterable<VariableElement> staticNonFinalFields =
- handler.getStaticNonFinalFieldsForEmission();
- for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
- compiler.withCurrentElement(element, () {
- jsAst.Expression initialValue;
- if (outputUnit !=
- compiler.deferredLoadTask.outputUnitForElement(element)) {
- if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) {
- // In the main output-unit we output a stub initializer for deferred
- // variables, such that `isolateProperties` stays a fast object.
- initialValue = jsAst.number(0);
- } else {
- // Don't output stubs outside the main output file.
- return;
- }
- } else {
- initialValue = constantEmitter.referenceInInitializationContext(
- handler.getInitialValueFor(element).value);
+ Iterable<Element> fields = task.outputStaticNonFinalFieldLists[outputUnit];
+ // If the outputUnit does not contain any static non-final fields, then
+ // [fields] is `null`.
+ if (fields != null) {
+ for (Element element in fields) {
+ compiler.withCurrentElement(element, () {
+ ConstantValue constant = handler.getInitialValueFor(element).value;
+ emitInitialization(
+ element,
+ constantEmitter.referenceInInitializationContext(constant));
+ });
+ }
+ }
+
+ if (inMainUnit && task.outputStaticNonFinalFieldLists.length > 1) {
+ // In the main output-unit we output a stub initializer for deferred
+ // variables, so that `isolateProperties` stays a fast object.
+ task.outputStaticNonFinalFieldLists.forEach(
+ (OutputUnit fieldsOutputUnit, Iterable<VariableElement> fields) {
+ if (fieldsOutputUnit == outputUnit) return; // Skip the main unit.
+ for (Element element in fields) {
+ compiler.withCurrentElement(element, () {
+ emitInitialization(element, jsAst.number(0));
+ });
}
- jsAst.Expression init =
- js('$isolateProperties.# = #',
- [namer.getNameOfGlobalField(element), initialValue]);
- buffer.write(jsAst.prettyPrint(init, compiler,
- monitor: compiler.dumpInfoTask));
- buffer.write('$N');
});
}
}
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/code_emitter_task.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698