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

Unified Diff: runtime/vm/parser.cc

Issue 1819673002: vm: Avoid list allocation for empty map literals (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 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: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index 1aa98b144985022265652f73f90afa68bc1db8c0..660a73176eb8d75e4b02af82fa14e7534ca32fb5 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -13054,12 +13054,20 @@ AstNode* Parser::ParseMapLiteral(TokenPosition type_pos,
factory_type_args = factory_type_args.Canonicalize();
ArgumentListNode* factory_param = new(Z) ArgumentListNode(literal_pos);
// The kv_pair array is temporary and of element type dynamic. It is passed
- // to the factory to initialize a properly typed map.
- ArrayNode* kv_pairs = new(Z) ArrayNode(
- TokenPos(),
- Type::ZoneHandle(Z, Type::ArrayType()),
- kv_pairs_list);
- factory_param->Add(kv_pairs);
+ // to the factory to initialize a properly typed map. Pass a pre-allocated
+ // array for the common empty map literal case.
+ if (kv_pairs_list.length() == 0) {
+ LiteralNode* empty_array_literal =
+ new(Z) LiteralNode(TokenPos(), Object::empty_array());
+ factory_param->Add(empty_array_literal);
+ } else {
+ ArrayNode* kv_pairs = new(Z) ArrayNode(
+ TokenPos(),
+ Type::ZoneHandle(Z, Type::ArrayType()),
+ kv_pairs_list);
+ factory_param->Add(kv_pairs);
+ }
+
return CreateConstructorCallNode(literal_pos,
factory_type_args,
factory_method,
« 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