Revision: 24873
Author:   [email protected]
Date:     Fri Oct 24 13:02:23 2014 UTC
Log: AstValueFactory: make true, false, null, undefined and "the hole" unique values.

They were not, so we were creating several instances of them, one for each time
they occurred in the source code.

It's not known to have caused efficiency problems though, so this is a sanity
fix more than an efficiency fix.

Note that numbers are still not unique.

BUG=
[email protected]

Review URL: https://codereview.chromium.org/657893003
https://code.google.com/p/v8/source/detail?r=24873

Modified:
 /branches/bleeding_edge/src/ast-value-factory.cc
 /branches/bleeding_edge/src/ast-value-factory.h

=======================================
--- /branches/bleeding_edge/src/ast-value-factory.cc Thu Oct 2 13:05:11 2014 UTC +++ /branches/bleeding_edge/src/ast-value-factory.cc Fri Oct 24 13:02:23 2014 UTC
@@ -328,15 +328,25 @@
   values_.Add(value);
   return value;
 }
+
+
+#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,34 +362,21 @@


 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) {
=======================================
--- /branches/bleeding_edge/src/ast-value-factory.h Tue Oct 21 12:16:37 2014 UTC +++ /branches/bleeding_edge/src/ast-value-factory.h Fri Oct 24 13:02:23 2014 UTC
@@ -238,7 +238,7 @@
 };


-// For generating string constants.
+// For generating constants.
 #define STRING_CONSTANTS(F)                           \
   F(anonymous_function, "(anonymous function)")       \
   F(arguments, "arguments")                           \
@@ -268,6 +268,12 @@
   F(use_strict, "use strict")                         \
   F(value, "value")

+#define OTHER_CONSTANTS(F) \
+  F(true_value)            \
+  F(false_value)           \
+  F(null_value)            \
+  F(undefined_value)       \
+  F(the_hole_value)

 class AstValueFactory {
  public:
@@ -276,10 +282,12 @@
         zone_(zone),
         isolate_(NULL),
         hash_seed_(hash_seed) {
-#define F(name, str) \
-    name##_string_ = NULL;
+#define F(name, str) name##_string_ = NULL;
     STRING_CONSTANTS(F)
 #undef F
+#define F(name) name##_ = NULL;
+    OTHER_CONSTANTS(F)
+#undef F
   }

   Zone* zone() const { return zone_; }
@@ -299,15 +307,15 @@
     return isolate_ != NULL;
   }

-#define F(name, str) \
-  const AstRawString* name##_string() { \
-    if (name##_string_ == NULL) { \
-      const char* data = str; \
-      name##_string_ = GetOneByteString( \
+#define F(name, str)                                                    \
+  const AstRawString* name##_string() {                                 \
+    if (name##_string_ == NULL) {                                       \
+      const char* data = str;                                           \
+      name##_string_ = GetOneByteString(                                \
           Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(data), \
-                                static_cast<int>(strlen(data)))); \
-    } \
-    return name##_string_; \
+                                static_cast<int>(strlen(data))));       \
+    }                                                                   \
+    return name##_string_;                                              \
   }
   STRING_CONSTANTS(F)
 #undef F
@@ -338,10 +346,13 @@

   uint32_t hash_seed_;

-#define F(name, str) \
-  const AstRawString* name##_string_;
+#define F(name, str) const AstRawString* name##_string_;
   STRING_CONSTANTS(F)
 #undef F
+
+#define F(name) AstValue* name##_;
+  OTHER_CONSTANTS(F)
+#undef F
 };


@@ -351,5 +362,6 @@
 } }  // namespace v8::internal

 #undef STRING_CONSTANTS
+#undef OTHER_CONSTANTS

 #endif  // V8_AST_VALUE_FACTORY_H_

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to