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

Unified Diff: runtime/vm/parser.cc

Issue 1327003003: Cache interpolated constant strings (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add a comment Created 5 years, 3 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 029eb9317aebd6ffcb333b3c2aa393b9f8dbeb55..33bfffc157f8fa7da7f7f740f61f007a54b0615f 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -13589,6 +13589,16 @@ AstNode* Parser::ParseStringLiteral(bool allow_interpolation) {
return primary;
}
// String interpolation needed.
+
+ // First, check whether we've cached a compile-time constant for this
+ // string interpolation.
+ Instance& cached_string = Instance::Handle(Z);
+ if (GetCachedConstant(literal_start, &cached_string)) {
+ SkipStringLiteral();
+ return new(Z) LiteralNode(literal_start,
+ Instance::ZoneHandle(Z, cached_string.raw()));
+ }
+
bool is_compiletime_const = true;
bool has_interpolation = false;
GrowableArray<AstNode*> values_list;
@@ -13641,7 +13651,9 @@ AstNode* Parser::ParseStringLiteral(bool allow_interpolation) {
}
if (is_compiletime_const) {
if (has_interpolation) {
- primary = new(Z) LiteralNode(literal_start, Interpolate(values_list));
+ const String& interpolated_string = Interpolate(values_list);
+ primary = new(Z) LiteralNode(literal_start, interpolated_string);
+ CacheConstantValue(literal_start, interpolated_string);
} else {
GrowableHandlePtrArray<const String> pieces(Z, values_list.length());
for (int i = 0; i < values_list.length(); i++) {
@@ -13651,6 +13663,8 @@ AstNode* Parser::ParseStringLiteral(bool allow_interpolation) {
}
const String& lit = String::ZoneHandle(Z, Symbols::FromConcatAll(pieces));
primary = new(Z) LiteralNode(literal_start, lit);
+ // Caching of constant not necessary because the symbol lookup will
+ // find the value next time.
}
} else {
ArrayNode* values = new(Z) ArrayNode(
« 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