Index: src/ast/ast-value-factory.cc |
diff --git a/src/ast/ast-value-factory.cc b/src/ast/ast-value-factory.cc |
index f6ead8d6e4c9ca436652ce6018aa1be21131b8c9..a18f6141cf78079595527d1dfd9c402612571acb 100644 |
--- a/src/ast/ast-value-factory.cc |
+++ b/src/ast/ast-value-factory.cc |
@@ -97,7 +97,6 @@ void AstString::Internalize(Isolate* isolate) { |
} |
void AstRawString::Internalize(Isolate* isolate) { |
- if (!string_.is_null()) return; |
if (literal_bytes_.length() == 0) { |
string_ = isolate->factory()->empty_string(); |
} else { |
@@ -106,18 +105,19 @@ void AstRawString::Internalize(Isolate* isolate) { |
} |
} |
-bool AstRawString::AsArrayIndex(uint32_t* index, |
- HandleDereferenceMode deref_mode) const { |
- if (deref_mode == HandleDereferenceMode::kAllowed && !string_.is_null()) |
- return string_->AsArrayIndex(index); |
- if (!is_one_byte() || literal_bytes_.length() == 0 || |
- literal_bytes_.length() > String::kMaxArrayIndexSize) |
- return false; |
- OneByteStringStream stream(literal_bytes_); |
- return StringToArrayIndex(&stream, index); |
+bool AstRawString::AsArrayIndex(uint32_t* index) const { |
+ // The StringHasher will set up the hash in such a way that we can use it to |
+ // figure out whether the string is convertible to an array index. |
+ if ((hash_ & Name::kIsNotArrayIndexMask) != 0) return false; |
+ if (length() <= Name::kMaxCachedArrayIndexLength) { |
+ *index = Name::ArrayIndexValueBits::decode(hash_); |
+ } else { |
+ OneByteStringStream stream(literal_bytes_); |
+ CHECK(StringToArrayIndex(&stream, index)); |
+ } |
+ return true; |
} |
- |
bool AstRawString::IsOneByteEqualTo(const char* data) const { |
int length = static_cast<int>(strlen(data)); |
if (is_one_byte() && literal_bytes_.length() == length) { |
@@ -136,10 +136,10 @@ void AstConsString::Internalize(Isolate* isolate) { |
.ToHandleChecked(); |
} |
-bool AstValue::IsPropertyName(HandleDereferenceMode deref_mode) const { |
+bool AstValue::IsPropertyName() const { |
if (type_ == STRING) { |
uint32_t index; |
- return !string_->AsArrayIndex(&index, deref_mode); |
+ return !string_->AsArrayIndex(&index); |
} |
return false; |
} |
@@ -251,7 +251,13 @@ const AstRawString* AstValueFactory::GetString(Handle<String> literal) { |
} |
} |
isolate_ = saved_isolate; |
- if (isolate_) result->Internalize(isolate_); |
+ if (strings_ != nullptr && isolate_) { |
+ // Only the string we are creating is uninternalized at this point. |
+ DCHECK_EQ(result, strings_); |
+ DCHECK_NULL(strings_->next()); |
+ result->Internalize(isolate_); |
+ ResetStrings(); |
+ } |
return result; |
} |
@@ -262,85 +268,68 @@ const AstConsString* AstValueFactory::NewConsString( |
// the AstRawString will not be moved). |
AstConsString* new_string = new (zone_) AstConsString(left, right); |
CHECK(new_string != nullptr); |
- strings_.Add(new_string); |
- if (isolate_) { |
- new_string->Internalize(isolate_); |
- } |
+ AddString(new_string); |
return new_string; |
} |
void AstValueFactory::Internalize(Isolate* isolate) { |
if (isolate_) { |
+ DCHECK_NULL(strings_); |
+ DCHECK_NULL(values_); |
// Everything is already internalized. |
return; |
} |
// Strings need to be internalized before values, because values refer to |
// strings. |
- for (int i = 0; i < strings_.length(); ++i) { |
- strings_[i]->Internalize(isolate); |
+ for (AstString* current = strings_; current != nullptr;) { |
+ AstString* next = current->next(); |
+ current->Internalize(isolate); |
+ current = next; |
} |
- for (int i = 0; i < values_.length(); ++i) { |
- values_[i]->Internalize(isolate); |
+ for (AstValue* current = values_; current != nullptr;) { |
+ AstValue* next = current->next(); |
+ current->Internalize(isolate); |
+ current = next; |
} |
isolate_ = isolate; |
+ ResetStrings(); |
+ values_ = nullptr; |
} |
const AstValue* AstValueFactory::NewString(const AstRawString* string) { |
AstValue* value = new (zone_) AstValue(string); |
CHECK(string != nullptr); |
- if (isolate_) { |
- value->Internalize(isolate_); |
- } |
- values_.Add(value); |
- return value; |
+ return AddValue(value); |
} |
const AstValue* AstValueFactory::NewSymbol(const char* name) { |
AstValue* value = new (zone_) AstValue(name); |
- if (isolate_) { |
- value->Internalize(isolate_); |
- } |
- values_.Add(value); |
- return value; |
+ return AddValue(value); |
} |
const AstValue* AstValueFactory::NewNumber(double number, bool with_dot) { |
AstValue* value = new (zone_) AstValue(number, with_dot); |
- if (isolate_) { |
- value->Internalize(isolate_); |
- } |
- values_.Add(value); |
- return value; |
+ return AddValue(value); |
} |
const AstValue* AstValueFactory::NewSmi(int number) { |
AstValue* value = |
new (zone_) AstValue(AstValue::SMI, number); |
- if (isolate_) { |
- value->Internalize(isolate_); |
- } |
- values_.Add(value); |
- return value; |
+ return AddValue(value); |
} |
- |
-#define GENERATE_VALUE_GETTER(value, initializer) \ |
- if (!value) { \ |
- value = new (zone_) AstValue(initializer); \ |
- if (isolate_) { \ |
- value->Internalize(isolate_); \ |
- } \ |
- values_.Add(value); \ |
- } \ |
+#define GENERATE_VALUE_GETTER(value, initializer) \ |
+ if (!value) { \ |
+ value = AddValue(new (zone_) AstValue(initializer)); \ |
+ } \ |
return value; |
- |
const AstValue* AstValueFactory::NewBoolean(bool b) { |
if (b) { |
GENERATE_VALUE_GETTER(true_value_, true); |
@@ -384,10 +373,7 @@ AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, |
is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
CHECK(new_string != nullptr); |
entry->key = new_string; |
- strings_.Add(new_string); |
- if (isolate_) { |
- new_string->Internalize(isolate_); |
- } |
+ AddString(new_string); |
entry->value = reinterpret_cast<void*>(1); |
} |
return reinterpret_cast<AstRawString*>(entry->key); |