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

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

Issue 657893003: AstValueFactory: make true, false, null, undefined and "the hole" unique values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: oops Created 6 years, 2 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 | « src/ast-value-factory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast-value-factory.cc
diff --git a/src/ast-value-factory.cc b/src/ast-value-factory.cc
index 4df6ac01a03a7ddef1fa401c6b0707677bc1950b..0a1949a69cc2b05756aa1939e1d947ebffae2b12 100644
--- a/src/ast-value-factory.cc
+++ b/src/ast-value-factory.cc
@@ -330,13 +330,23 @@ const AstValue* AstValueFactory::NewSmi(int number) {
}
+#define GENERATE_VALUE_GETTER(value, initializer) \
+ if (!value) { \
+ value = new (zone_) AstValue(initializer); \
+ if (isolate_) { \
+ value->Internalize(isolate_); \
+ } \
+ values_.Add(value); \
+ } \
+ return value;
+
+
const AstValue* AstValueFactory::NewBoolean(bool b) {
- AstValue* value = new (zone_) AstValue(b);
- if (isolate_) {
- value->Internalize(isolate_);
+ if (b) {
+ GENERATE_VALUE_GETTER(true_value_, true);
+ } else {
+ GENERATE_VALUE_GETTER(false_value_, false);
}
- values_.Add(value);
- return value;
}
@@ -352,35 +362,22 @@ const AstValue* AstValueFactory::NewStringList(
const AstValue* AstValueFactory::NewNull() {
- AstValue* value = new (zone_) AstValue(AstValue::NULL_TYPE);
- if (isolate_) {
- value->Internalize(isolate_);
- }
- values_.Add(value);
- return value;
+ GENERATE_VALUE_GETTER(null_value_, AstValue::NULL_TYPE);
}
const AstValue* AstValueFactory::NewUndefined() {
- AstValue* value = new (zone_) AstValue(AstValue::UNDEFINED);
- if (isolate_) {
- value->Internalize(isolate_);
- }
- values_.Add(value);
- return value;
+ GENERATE_VALUE_GETTER(undefined_value_, AstValue::UNDEFINED);
}
const AstValue* AstValueFactory::NewTheHole() {
- AstValue* value = new (zone_) AstValue(AstValue::THE_HOLE);
- if (isolate_) {
- value->Internalize(isolate_);
- }
- values_.Add(value);
- return value;
+ GENERATE_VALUE_GETTER(the_hole_value_, AstValue::THE_HOLE);
}
+#undef GENERATE_VALUE_GETTER
+
const AstRawString* AstValueFactory::GetString(
uint32_t hash, bool is_one_byte, Vector<const byte> literal_bytes) {
// literal_bytes here points to whatever the user passed, and this is OK
« no previous file with comments | « src/ast-value-factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698