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

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

Issue 999933007: dart2js: emit info on lazy fields in array. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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: 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 e05d1df1d8847e3dc77fcabd367e338640a928f4..9b63eae8bb31a92c7a89e1c5c37f897946fc8875 100644
--- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart
@@ -852,36 +852,49 @@ class OldEmitter implements Emitter {
handler.getLazilyInitializedFieldsForEmission();
if (!lazyFields.isEmpty) {
needsLazyInitializer = true;
- for (VariableElement element in Elements.sortedByPosition(lazyFields)) {
- jsAst.Expression init =
- buildLazilyInitializedStaticField(element, isolateProperties);
- if (init == null) continue;
- output.addBuffer(
- jsAst.prettyPrint(init, compiler, monitor: compiler.dumpInfoTask));
- output.add("$N");
- }
+ List<jsAst.Expression> laziesInfo = buildLaziesInfo(lazyFields);
+ jsAst.Statement code = js.statement('''
+ {
herhut 2015/04/01 07:43:05 Why the block? If you were hoping for a new variab
zarah 2015/04/01 11:05:08 No it was to have a single statement. Changed it t
+ var lazies = #laziesInfo;
+ for (var i = 0; i < lazies.length; i += 5) {
+ var prototype = lazies[i];
+ var staticName = lazies[i + 1];
+ var fieldName = lazies [i + 2];
+ var getterName = lazies[i + 3];
+ var lazyValue = lazies[i + 4];
+
+ // We build the lazy-check here:
+ // lazyInitializer(prototype, staticName, fieldName, getterName,
+ // lazyValue);
+ // The staticName is used for error reporting. The 'lazyValue' must
+ // be a closure that constructs the initial value.
+ #lazy(prototype, staticName, fieldName, getterName, lazyValue);
herhut 2015/04/01 07:43:05 This has become a little more complicated now, as
zarah 2015/04/01 11:05:08 Changed to handle this.
+ }
+ }
+ ''', {'laziesInfo': new jsAst.ArrayInitializer(laziesInfo),
+ 'lazy': js(lazyInitializerName)});
+
+ output.addBuffer(
+ jsAst.prettyPrint(code, compiler, monitor: compiler.dumpInfoTask));
+ output.add("$N");
}
}
- jsAst.Expression buildLazilyInitializedStaticField(
- VariableElement element, String isolateProperties) {
- jsAst.Expression code = backend.generatedCode[element];
- // The code is null if we ended up not needing the lazily
- // initialized field after all because of constant folding
- // before code generation.
- if (code == null) return null;
- // The code only computes the initial value. We build the lazy-check
- // here:
- // lazyInitializer(prototype, 'name', fieldName, getterName, initial);
- // The name is used for error reporting. The 'initial' must be a
- // closure that constructs the initial value.
- return js('#(#,#,#,#,#)',
- [js(lazyInitializerName),
- js(isolateProperties),
- js.string(element.name),
- js.string(namer.globalPropertyName(element)),
- js.string(namer.lazyInitializerName(element)),
- code]);
+ List<jsAst.Expression> buildLaziesInfo(List<VariableElement> lazies) {
+ List<jsAst.Expression> laziesInfo = <jsAst.Expression>[];
+ for (VariableElement element in Elements.sortedByPosition(lazies)) {
+ jsAst.Expression code = backend.generatedCode[element];
+ // The code is null if we ended up not needing the lazily
+ // initialized field after all because of constant folding
+ // before code generation.
+ if (code == null) continue;
+ laziesInfo.addAll([js(isolateProperties),
+ js.string(element.name),
floitsch 2015/03/24 16:28:17 nit: indentation seems off.
zarah 2015/04/01 11:05:08 Done.
+ js.string(namer.globalPropertyName(element)),
+ js.string(namer.lazyInitializerName(element)),
+ code]);
+ }
+ return laziesInfo;
}
void emitMetadata(Program program, CodeOutput output) {
« 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