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

Unified Diff: runtime/vm/parser.cc

Issue 1303973007: Moar constant caching (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: less moar Created 5 years, 4 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 | « runtime/vm/parser.h ('k') | 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 f7e3a273d4def38aee2bb6b2c1ce9a7f6f1ca575..284357914338b70ad568f6fcb7ebdcdb02fb52ad 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -10633,9 +10633,9 @@ AstNode* Parser::ExpandAssignableOp(intptr_t op_pos,
// Evaluates the value of the compile time constant expression
// and returns a literal node for the value.
-AstNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) {
+LiteralNode* Parser::FoldConstExpr(intptr_t expr_pos, AstNode* expr) {
if (expr->IsLiteralNode()) {
- return expr;
+ return expr->AsLiteralNode();
}
if (expr->EvalConstExpr() == NULL) {
ReportError(expr_pos, "expression is not a valid compile-time constant");
@@ -10882,13 +10882,27 @@ AstNode* Parser::ParseExpr(bool require_compiletime_const,
AstNode* expr = ParseExpr(require_compiletime_const, consume_cascades);
return new(Z) ThrowNode(expr_pos, expr, NULL);
}
+
+ if (require_compiletime_const) {
srdjan 2015/09/01 21:33:51 How about skipping lookup if expr->IsLiteralNode()
hausner 2015/09/01 21:37:38 The lookup happens before the expression is parsed
+ // Check whether we already have evaluated a compile-time constant
+ // at this source location.
+ Instance& existing_const = Instance::ZoneHandle(Z);
+ if (GetCachedConstant(expr_pos, &existing_const)) {
+ SkipConditionalExpr();
+ return new(Z) LiteralNode(expr_pos, existing_const);
+ }
+ }
+
AstNode* expr = ParseConditionalExpr();
if (!Token::IsAssignmentOperator(CurrentToken())) {
if ((CurrentToken() == Token::kCASCADE) && consume_cascades) {
return ParseCascades(expr);
}
if (require_compiletime_const) {
- expr = FoldConstExpr(expr_pos, expr);
+ const bool use_cache = !expr->IsLiteralNode();
+ LiteralNode* const_value = FoldConstExpr(expr_pos, expr);
+ if (use_cache) CacheConstantValue(expr_pos, const_value->literal());
+ expr = const_value;
} else {
expr = LiteralIfStaticConst(Z, expr);
}
« no previous file with comments | « runtime/vm/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698