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

Unified Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1616143003: Lower map literals to constructor or function calls in builder (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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 | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
diff --git a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
index c4ce556be84ffa6eaae42a0073f37fe993a4cdc9..68e7e4ede814002bff1765b7b000b41cd87e1ece 100644
--- a/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
+++ b/pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart
@@ -1334,12 +1334,48 @@ class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
if (node.isConst) {
return translateConstant(node);
}
+
InterfaceType type = elements.getType(node);
- List<ir.LiteralMapEntry> entries =
- node.entries.nodes.mapToList((ast.LiteralMapEntry e) {
- return new ir.LiteralMapEntry(visit(e.key), visit(e.value));
- });
- return irBuilder.addPrimitive(new ir.LiteralMap(type, entries));
+
+ if (node.entries.nodes.isEmpty) {
+ if (type.treatAsRaw) {
+ return irBuilder.buildStaticFunctionInvocation(
+ helpers.mapLiteralUntypedEmptyMaker,
+ <ir.Primitive>[],
+ sourceInformation: sourceInformationBuilder.buildNew(node));
+ } else {
+ ConstructorElement constructor = helpers.mapLiteralConstructorEmpty;
+ return irBuilder.buildConstructorInvocation(
+ constructor.effectiveTarget,
+ CallStructure.NO_ARGS,
+ constructor.computeEffectiveTargetType(type),
+ <ir.Primitive>[],
+ sourceInformationBuilder.buildNew(node));
+ }
+ }
+
+ List<ir.Primitive> keysAndValues = <ir.Primitive>[];
+ for (ast.LiteralMapEntry entry in node.entries.nodes.toList()) {
+ keysAndValues.add(visit(entry.key));
+ keysAndValues.add(visit(entry.value));
+ }
+ ir.Primitive keysAndValuesList =
+ irBuilder.buildListLiteral(null, keysAndValues);
+
+ if (type.treatAsRaw) {
+ return irBuilder.buildStaticFunctionInvocation(
+ helpers.mapLiteralUntypedMaker,
+ <ir.Primitive>[keysAndValuesList],
+ sourceInformation: sourceInformationBuilder.buildNew(node));
+ } else {
+ ConstructorElement constructor = helpers.mapLiteralConstructor;
+ return irBuilder.buildConstructorInvocation(
+ constructor.effectiveTarget,
+ CallStructure.ONE_ARG,
+ constructor.computeEffectiveTargetType(type),
+ <ir.Primitive>[keysAndValuesList],
+ sourceInformationBuilder.buildNew(node));
+ }
}
ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) {
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698