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

Unified Diff: runtime/vm/parser.cc

Issue 1311393010: Cache more constants (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add symbol constants to the cache 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 22df857e4b0737fca24cbb1c979534bed913ac3c..0328af02b25bf45c50d57897390d35751c251794 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -2591,9 +2591,12 @@ AstNode* Parser::ParseExternalInitializedField(const Field& field) {
} else {
init_expr = ParseExpr(kAllowConst, kConsumeCascades);
if (init_expr->EvalConstExpr() != NULL) {
- init_expr =
- new LiteralNode(field.token_pos(),
- EvaluateConstExpr(expr_pos, init_expr));
+ Instance& expr_value = Instance::ZoneHandle(Z);
+ if (!GetCachedConstant(expr_pos, &expr_value)) {
+ expr_value = EvaluateConstExpr(expr_pos, init_expr).raw();
+ CacheConstantValue(expr_pos, expr_value);
+ }
+ init_expr = new(Z) LiteralNode(field.token_pos(), expr_value);
}
}
set_current_class(saved_class);
@@ -2637,8 +2640,12 @@ void Parser::ParseInitializedInstanceFields(const Class& cls,
intptr_t expr_pos = TokenPos();
init_expr = ParseExpr(kAllowConst, kConsumeCascades);
if (init_expr->EvalConstExpr() != NULL) {
- init_expr = new LiteralNode(field.token_pos(),
- EvaluateConstExpr(expr_pos, init_expr));
+ Instance& expr_value = Instance::ZoneHandle(Z);
+ if (!GetCachedConstant(expr_pos, &expr_value)) {
+ expr_value = EvaluateConstExpr(expr_pos, init_expr).raw();
+ CacheConstantValue(expr_pos, expr_value);
+ }
+ init_expr = new(Z) LiteralNode(field.token_pos(), expr_value);
}
}
}
@@ -13040,6 +13047,11 @@ AstNode* Parser::ParseSymbolLiteral() {
ReportError("illegal symbol literal");
}
+ Instance& symbol_instance = Instance::ZoneHandle(Z);
+ if (GetCachedConstant(symbol_pos, &symbol_instance)) {
+ return new(Z) LiteralNode(symbol_pos, symbol_instance);
+ }
+
// Call Symbol class constructor to create a symbol instance.
const Class& symbol_class = Class::Handle(I->object_store()->symbol_class());
ASSERT(!symbol_class.IsNull());
@@ -13059,9 +13071,9 @@ AstNode* Parser::ParseSymbolLiteral() {
script_, symbol_pos,
"error executing const Symbol constructor");
}
- const Instance& instance = Instance::Cast(result);
- return new(Z) LiteralNode(symbol_pos,
- Instance::ZoneHandle(Z, instance.raw()));
+ symbol_instance ^= result.raw();
+ CacheConstantValue(symbol_pos, symbol_instance);
+ return new(Z) LiteralNode(symbol_pos, symbol_instance);
}
« 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