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

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

Issue 2687933003: [Parser] Cache and clone initial AstValueFactory string_table_. (Closed)
Patch Set: Address comments Created 3 years, 10 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 2e791416291b8fc534a7b42a8d9dd58ce3afe734..a85deb060af2d48a7cb63433c0dd635c444afe42 100644
--- a/src/ast/ast-value-factory.h
+++ b/src/ast/ast-value-factory.h
@@ -106,6 +106,8 @@ class AstRawString final : public AstString {
return *c;
}
+ static bool Compare(void* a, void* b);
+
// For storing AstRawStrings in a hash map.
uint32_t hash() const {
return hash_;
@@ -336,7 +338,9 @@ class AstValue : public ZoneObject {
class AstStringConstants final {
public:
AstStringConstants(Isolate* isolate, uint32_t hash_seed)
- : zone_(isolate->allocator(), ZONE_NAME), hash_seed_(hash_seed) {
+ : zone_(isolate->allocator(), ZONE_NAME),
+ string_table_(AstRawString::Compare),
+ hash_seed_(hash_seed) {
DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
#define F(name, str) \
{ \
@@ -349,20 +353,28 @@ class AstStringConstants final {
/* 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()); \
+ base::HashMap::Entry* entry = \
+ string_table_.InsertNew(name##_string_, name##_string_->hash()); \
+ DCHECK(entry->value == nullptr); \
+ entry->value = reinterpret_cast<void*>(1); \
}
STRING_CONSTANTS(F)
#undef F
}
#define F(name, str) \
- AstRawString* name##_string() { return name##_string_; }
+ const AstRawString* name##_string() const { return name##_string_; }
STRING_CONSTANTS(F)
#undef F
uint32_t hash_seed() const { return hash_seed_; }
+ const base::CustomMatcherHashMap* string_table() const {
+ return &string_table_;
+ }
private:
Zone zone_;
+ base::CustomMatcherHashMap string_table_;
uint32_t hash_seed_;
#define F(name, str) AstRawString* name##_string_;
@@ -381,9 +393,9 @@ class AstStringConstants final {
class AstValueFactory {
public:
- AstValueFactory(Zone* zone, AstStringConstants* string_constants,
+ AstValueFactory(Zone* zone, const AstStringConstants* string_constants,
uint32_t hash_seed)
- : string_table_(AstRawStringCompare),
+ : string_table_(string_constants->string_table()),
values_(nullptr),
strings_(nullptr),
strings_end_(&strings_),
@@ -398,7 +410,6 @@ class AstValueFactory {
std::fill(one_character_strings_,
one_character_strings_ + arraysize(one_character_strings_),
nullptr);
- InitializeStringConstants();
}
Zone* zone() const { return zone_; }
@@ -462,19 +473,6 @@ class AstValueFactory {
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).
base::CustomMatcherHashMap string_table_;
// For keeping track of all AstValues and AstRawStrings we've created (so that
@@ -487,7 +485,7 @@ class AstValueFactory {
AstString** strings_end_;
// Holds constant string values which are shared across the isolate.
- AstStringConstants* string_constants_;
+ const AstStringConstants* string_constants_;
// Caches for faster access: small numbers, one character lowercase strings
// (for minified code).
« 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