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

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

Issue 2638783002: Revert of [Parser] Introduce AstStringConstants to share constants across AstValueFactory (Closed)
Patch Set: Created 3 years, 11 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 | src/ast/ast-value-factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast-value-factory.h
diff --git a/src/ast/ast-value-factory.h b/src/ast/ast-value-factory.h
index fd9ed7116716df207993552160e2e0451441882b..8b28c5e4bc4976a2a26077bf5fbacac4ab4a2052 100644
--- a/src/ast/ast-value-factory.h
+++ b/src/ast/ast-value-factory.h
@@ -111,9 +111,8 @@
}
private:
+ friend class AstValueFactory;
friend class AstRawStringInternalizationKey;
- friend class AstStringConstants;
- friend class AstValueFactory;
AstRawString(bool is_one_byte, const Vector<const byte>& literal_bytes,
uint32_t hash)
@@ -292,6 +291,7 @@
const char* symbol_name_;
};
};
+
// For generating constants.
#define STRING_CONSTANTS(F) \
@@ -332,45 +332,6 @@
F(use_strict, "use strict") \
F(value, "value")
-class AstStringConstants final {
- public:
- AstStringConstants(Isolate* isolate, uint32_t hash_seed)
- : zone_(isolate->allocator(), ZONE_NAME), hash_seed_(hash_seed) {
- DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
-#define F(name, str) \
- { \
- const char* data = str; \
- Vector<const uint8_t> literal(reinterpret_cast<const uint8_t*>(data), \
- static_cast<int>(strlen(data))); \
- uint32_t hash = StringHasher::HashSequentialString<uint8_t>( \
- literal.start(), literal.length(), hash_seed_); \
- name##_string_ = new (&zone_) AstRawString(true, literal, hash); \
- /* The Handle returned by the factory is located on the roots */ \
- /* array, not on the temporary HandleScope, so this is safe. */ \
- name##_string_->set_string(isolate->factory()->name##_string()); \
- }
- STRING_CONSTANTS(F)
-#undef F
- }
-
-#define F(name, str) \
- AstRawString* name##_string() { return name##_string_; }
- STRING_CONSTANTS(F)
-#undef F
-
- uint32_t hash_seed() const { return hash_seed_; }
-
- private:
- Zone zone_;
- uint32_t hash_seed_;
-
-#define F(name, str) AstRawString* name##_string_;
- STRING_CONSTANTS(F)
-#undef F
-
- DISALLOW_COPY_AND_ASSIGN(AstStringConstants);
-};
-
#define OTHER_CONSTANTS(F) \
F(true_value) \
F(false_value) \
@@ -380,24 +341,23 @@
class AstValueFactory {
public:
- AstValueFactory(Zone* zone, AstStringConstants* string_constants,
- uint32_t hash_seed)
+ AstValueFactory(Zone* zone, uint32_t hash_seed)
: string_table_(AstRawStringCompare),
values_(nullptr),
strings_(nullptr),
strings_end_(&strings_),
- string_constants_(string_constants),
zone_(zone),
hash_seed_(hash_seed) {
-#define F(name) name##_ = nullptr;
+#define F(name, str) name##_string_ = NULL;
+ STRING_CONSTANTS(F)
+#undef F
+#define F(name) name##_ = NULL;
OTHER_CONSTANTS(F)
#undef F
- DCHECK_EQ(hash_seed, string_constants->hash_seed());
std::fill(smis_, smis_ + arraysize(smis_), nullptr);
std::fill(one_character_strings_,
one_character_strings_ + arraysize(one_character_strings_),
nullptr);
- InitializeStringConstants();
}
Zone* zone() const { return zone_; }
@@ -418,9 +378,15 @@
void Internalize(Isolate* isolate);
-#define F(name, str) \
- const AstRawString* name##_string() { \
- return string_constants_->name##_string(); \
+#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_; \
}
STRING_CONSTANTS(F)
#undef F
@@ -461,17 +427,6 @@
AstRawString* GetString(uint32_t hash, bool is_one_byte,
Vector<const byte> literal_bytes);
- void InitializeStringConstants() {
-#define F(name, str) \
- AstRawString* raw_string_##name = string_constants_->name##_string(); \
- base::HashMap::Entry* entry_##name = string_table_.LookupOrInsert( \
- raw_string_##name, raw_string_##name->hash()); \
- DCHECK(entry_##name->value == nullptr); \
- entry_##name->value = reinterpret_cast<void*>(1);
- STRING_CONSTANTS(F)
-#undef F
- }
-
static bool AstRawStringCompare(void* a, void* b);
// All strings are copied here, one after another (no NULLs inbetween).
@@ -485,9 +440,6 @@
AstString* strings_;
AstString** strings_end_;
- // Holds constant string values which are shared across the isolate.
- AstStringConstants* string_constants_;
-
// Caches for faster access: small numbers, one character lowercase strings
// (for minified code).
AstValue* smis_[kMaxCachedSmi + 1];
@@ -496,6 +448,10 @@
Zone* zone_;
uint32_t hash_seed_;
+
+#define F(name, str) const AstRawString* name##_string_;
+ STRING_CONSTANTS(F)
+#undef F
#define F(name) AstValue* name##_;
OTHER_CONSTANTS(F)
« no previous file with comments | « no previous file | src/ast/ast-value-factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698