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

Unified Diff: lib/src/compiler/code_generator.dart

Issue 1998113004: Optimize const construction (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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 | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/operations.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/compiler/code_generator.dart
diff --git a/lib/src/compiler/code_generator.dart b/lib/src/compiler/code_generator.dart
index 478327afa187534277ced67e0120cd1f6b68d971..5b1a349a70d482c9a3f7b9d2a9e3001786e30ce0 100644
--- a/lib/src/compiler/code_generator.dart
+++ b/lib/src/compiler/code_generator.dart
@@ -829,7 +829,7 @@ class CodeGenerator extends GeneralizingAstVisitor
// Create static values list
var values = new JS.ArrayInitializer(new List<JS.Expression>.from(
fields.map((f) => js.call('#.#', [id, f.name]))));
- result.add(js.statement('#.values = dart.const(dart.list(#, #));',
+ result.add(js.statement('#.values = dart.constList(#, #);',
[id, values, _emitType(type)]));
return _statement(result);
@@ -3433,11 +3433,11 @@ class CodeGenerator extends GeneralizingAstVisitor
return id;
}
- JS.Expression _emitConst(JS.Expression expr()) {
+ JS.Expression _cacheConst(JS.Expression expr()) {
var savedTypeParams = _typeParamInConst;
_typeParamInConst = [];
- var jsExpr = js.call('dart.const(#)', expr());
+ var jsExpr = expr();
bool usesTypeParams = _typeParamInConst.isNotEmpty;
_typeParamInConst = savedTypeParams;
@@ -3451,6 +3451,9 @@ class CodeGenerator extends GeneralizingAstVisitor
_moduleItems.add(js.statement('let #;', [temp]));
return js.call('# || (# = #)', [temp, temp, jsExpr]);
}
+
+ JS.Expression _emitConst(JS.Expression expr()) =>
+ _cacheConst(() => js.call('dart.const(#)', expr()));
/// Returns a new expression, which can be be used safely *once* on the
/// left hand side, and *once* on the right side of an assignment.
@@ -4156,6 +4159,7 @@ class CodeGenerator extends GeneralizingAstVisitor
@override
visitListLiteral(ListLiteral node) {
+ var isConst = node.constKeyword != null;
JS.Expression emitList() {
JS.Expression list = new JS.ArrayInitializer(
_visitList(node.elements) as List<JS.Expression>);
@@ -4164,14 +4168,16 @@ class CodeGenerator extends GeneralizingAstVisitor
// TODO(jmesserly): analyzer will usually infer `List<Object>` because
// that is the least upper bound of the element types. So we rarely
// generate a plain `List<dynamic>` anymore.
- if (!elementType.isDynamic) {
+ if (!elementType.isDynamic || isConst) {
// dart.list helper internally depends on _interceptors.JSArray.
_declareBeforeUse(_jsArray);
- list = js.call('dart.list(#, #)', [list, _emitType(elementType)]);
+ var typeRep = _emitType(elementType);
+ var helper = (isConst) ? 'constList' : 'list';
+ list = js.call('dart.${helper}(#, #)', [list, typeRep]);
}
return list;
}
- if (node.constKeyword != null) return _emitConst(emitList);
+ if (isConst) return _cacheConst(emitList);
return emitList();
}
« no previous file with comments | « lib/runtime/dart_sdk.js ('k') | tool/input_sdk/private/ddc_runtime/operations.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698