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

Unified Diff: src/ast/ast-value-factory.cc

Issue 2485423002: Adding smi cache (Closed)
Patch Set: Changed signature to uint Created 4 years, 1 month 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
Index: src/ast/ast-value-factory.cc
diff --git a/src/ast/ast-value-factory.cc b/src/ast/ast-value-factory.cc
index 1e4ef7d37cd1ce5b4a0489b7938669e50c755c16..7673d98fd54e8fbfd7374918012550c63818aabd 100644
--- a/src/ast/ast-value-factory.cc
+++ b/src/ast/ast-value-factory.cc
@@ -330,11 +330,17 @@ const AstValue* AstValueFactory::NewNumber(double number, bool with_dot) {
return AddValue(value);
}
-
-const AstValue* AstValueFactory::NewSmi(int number) {
- AstValue* value =
- new (zone_) AstValue(AstValue::SMI, number);
- return AddValue(value);
+const AstValue* AstValueFactory::NewSmi(uint32_t number) {
vogelheim 2016/11/09 15:04:10 [nitpick, and purely a matter of personal preferen
+ if (number <= kMaxCachedSmi) {
+ if (smis_[number] == nullptr) {
+ AstValue* value = new (zone_) AstValue(AstValue::SMI, number);
+ smis_[number] = AddValue(value);
+ }
+ return smis_[number];
+ } else {
+ AstValue* value = new (zone_) AstValue(AstValue::SMI, number);
+ return AddValue(value);
+ }
}
#define GENERATE_VALUE_GETTER(value, initializer) \

Powered by Google App Engine
This is Rietveld 408576698