Chromium Code Reviews| Index: src/ast/ast-value-factory.cc |
| diff --git a/src/ast/ast-value-factory.cc b/src/ast/ast-value-factory.cc |
| index f15a8bd58802ae59888e6e41ad5566376d5fe8dd..6cdf33183e6385b97fc048261fdbcb2ae5cb7e33 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 { |
| @@ -108,13 +107,14 @@ void AstRawString::Internalize(Isolate* isolate) { |
| bool AstRawString::AsArrayIndex(uint32_t* index) const { |
| - if (!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); |
| + if ((hash_ & Name::kIsNotArrayIndexMask) != 0) return false; |
|
marja
2016/08/10 08:33:17
I was trying to follow which part sets this, and i
|
| + if (length() <= Name::kMaxCachedArrayIndexLength) { |
| + *index = Name::ArrayIndexValueBits::decode(hash_); |
| + } else { |
| + OneByteStringStream stream(literal_bytes_); |
| + CHECK(StringToArrayIndex(&stream, index)); |
| + } |
| + return true; |
| } |
| @@ -252,7 +252,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; |
| } |
| @@ -263,84 +269,67 @@ 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); |