| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 void AstString::Internalize(Isolate* isolate) { | 92 void AstString::Internalize(Isolate* isolate) { |
| 93 if (IsRawStringBits::decode(bit_field_)) { | 93 if (IsRawStringBits::decode(bit_field_)) { |
| 94 return reinterpret_cast<AstRawString*>(this)->Internalize(isolate); | 94 return reinterpret_cast<AstRawString*>(this)->Internalize(isolate); |
| 95 } | 95 } |
| 96 return reinterpret_cast<AstConsString*>(this)->Internalize(isolate); | 96 return reinterpret_cast<AstConsString*>(this)->Internalize(isolate); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void AstRawString::Internalize(Isolate* isolate) { | 99 void AstRawString::Internalize(Isolate* isolate) { |
| 100 // Skip over already internalized strings. |
| 101 if (!string_.is_null()) return; |
| 100 if (literal_bytes_.length() == 0) { | 102 if (literal_bytes_.length() == 0) { |
| 101 string_ = isolate->factory()->empty_string(); | 103 string_ = isolate->factory()->empty_string(); |
| 102 } else { | 104 } else { |
| 103 AstRawStringInternalizationKey key(this); | 105 AstRawStringInternalizationKey key(this); |
| 104 string_ = StringTable::LookupKey(isolate, &key); | 106 string_ = StringTable::LookupKey(isolate, &key); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool AstRawString::AsArrayIndex(uint32_t* index) const { | 110 bool AstRawString::AsArrayIndex(uint32_t* index) const { |
| 109 // The StringHasher will set up the hash in such a way that we can use it to | 111 // The StringHasher will set up the hash in such a way that we can use it to |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 return result; | 251 return result; |
| 250 } | 252 } |
| 251 | 253 |
| 252 | 254 |
| 253 const AstConsString* AstValueFactory::NewConsString( | 255 const AstConsString* AstValueFactory::NewConsString( |
| 254 const AstString* left, const AstString* right) { | 256 const AstString* left, const AstString* right) { |
| 255 // This Vector will be valid as long as the Collector is alive (meaning that | 257 // This Vector will be valid as long as the Collector is alive (meaning that |
| 256 // the AstRawString will not be moved). | 258 // the AstRawString will not be moved). |
| 257 AstConsString* new_string = new (zone_) AstConsString(left, right); | 259 AstConsString* new_string = new (zone_) AstConsString(left, right); |
| 258 CHECK(new_string != nullptr); | 260 CHECK(new_string != nullptr); |
| 259 AddString(new_string); | 261 AddConsString(new_string); |
| 260 return new_string; | 262 return new_string; |
| 261 } | 263 } |
| 262 | 264 |
| 263 const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left, | 265 const AstRawString* AstValueFactory::ConcatStrings(const AstRawString* left, |
| 264 const AstRawString* right) { | 266 const AstRawString* right) { |
| 265 int left_length = left->length(); | 267 int left_length = left->length(); |
| 266 int right_length = right->length(); | 268 int right_length = right->length(); |
| 267 const unsigned char* left_data = left->raw_data(); | 269 const unsigned char* left_data = left->raw_data(); |
| 268 const unsigned char* right_data = right->raw_data(); | 270 const unsigned char* right_data = right->raw_data(); |
| 269 if (left->is_one_byte() && right->is_one_byte()) { | 271 if (left->is_one_byte() && right->is_one_byte()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 288 } else { | 290 } else { |
| 289 memcpy(buffer + left_length, right_data, 2 * right_length); | 291 memcpy(buffer + left_length, right_data, 2 * right_length); |
| 290 } | 292 } |
| 291 Vector<const uint16_t> literal(buffer, left_length + right_length); | 293 Vector<const uint16_t> literal(buffer, left_length + right_length); |
| 292 return GetTwoByteStringInternal(literal); | 294 return GetTwoByteStringInternal(literal); |
| 293 } | 295 } |
| 294 } | 296 } |
| 295 | 297 |
| 296 void AstValueFactory::Internalize(Isolate* isolate) { | 298 void AstValueFactory::Internalize(Isolate* isolate) { |
| 297 // Strings need to be internalized before values, because values refer to | 299 // Strings need to be internalized before values, because values refer to |
| 298 // strings. | 300 // strings. Internalize flat strings before cons strings since cons strings |
| 299 for (AstString* current = strings_; current != nullptr;) { | 301 // may point to flat strings. |
| 300 AstString* next = current->next(); | 302 for (base::CustomMatcherHashMap::Entry* entry = string_table_.Start(); |
| 303 entry != nullptr; entry = string_table_.Next(entry)) { |
| 304 reinterpret_cast<AstRawString*>(entry->key)->Internalize(isolate); |
| 305 } |
| 306 |
| 307 for (AstConsString* current = cons_strings_; current != nullptr;) { |
| 308 AstConsString* next = current->next(); |
| 301 current->Internalize(isolate); | 309 current->Internalize(isolate); |
| 302 current = next; | 310 current = next; |
| 303 } | 311 } |
| 312 |
| 304 for (AstValue* current = values_; current != nullptr;) { | 313 for (AstValue* current = values_; current != nullptr;) { |
| 305 AstValue* next = current->next(); | 314 AstValue* next = current->next(); |
| 306 current->Internalize(isolate); | 315 current->Internalize(isolate); |
| 307 current = next; | 316 current = next; |
| 308 } | 317 } |
| 309 ResetStrings(); | 318 ResetConsStrings(); |
| 310 values_ = nullptr; | 319 values_ = nullptr; |
| 311 } | 320 } |
| 312 | 321 |
| 313 | 322 |
| 314 const AstValue* AstValueFactory::NewString(const AstRawString* string) { | 323 const AstValue* AstValueFactory::NewString(const AstRawString* string) { |
| 315 AstValue* value = new (zone_) AstValue(string); | 324 AstValue* value = new (zone_) AstValue(string); |
| 316 CHECK(string != nullptr); | 325 CHECK(string != nullptr); |
| 317 return AddValue(value); | 326 return AddValue(value); |
| 318 } | 327 } |
| 319 | 328 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 base::HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash); | 387 base::HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash); |
| 379 if (entry->value == NULL) { | 388 if (entry->value == NULL) { |
| 380 // Copy literal contents for later comparison. | 389 // Copy literal contents for later comparison. |
| 381 int length = literal_bytes.length(); | 390 int length = literal_bytes.length(); |
| 382 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 391 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
| 383 memcpy(new_literal_bytes, literal_bytes.start(), length); | 392 memcpy(new_literal_bytes, literal_bytes.start(), length); |
| 384 AstRawString* new_string = new (zone_) AstRawString( | 393 AstRawString* new_string = new (zone_) AstRawString( |
| 385 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 394 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
| 386 CHECK(new_string != nullptr); | 395 CHECK(new_string != nullptr); |
| 387 entry->key = new_string; | 396 entry->key = new_string; |
| 388 AddString(new_string); | |
| 389 entry->value = reinterpret_cast<void*>(1); | 397 entry->value = reinterpret_cast<void*>(1); |
| 390 } | 398 } |
| 391 return reinterpret_cast<AstRawString*>(entry->key); | 399 return reinterpret_cast<AstRawString*>(entry->key); |
| 392 } | 400 } |
| 393 | 401 |
| 394 | 402 |
| 395 bool AstValueFactory::AstRawStringCompare(void* a, void* b) { | 403 bool AstValueFactory::AstRawStringCompare(void* a, void* b) { |
| 396 const AstRawString* lhs = static_cast<AstRawString*>(a); | 404 const AstRawString* lhs = static_cast<AstRawString*>(a); |
| 397 const AstRawString* rhs = static_cast<AstRawString*>(b); | 405 const AstRawString* rhs = static_cast<AstRawString*>(b); |
| 398 DCHECK_EQ(lhs->hash(), rhs->hash()); | 406 DCHECK_EQ(lhs->hash(), rhs->hash()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 417 length) == 0; | 425 length) == 0; |
| 418 } else { | 426 } else { |
| 419 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), | 427 return CompareCharsUnsigned(reinterpret_cast<const uint16_t*>(l), |
| 420 reinterpret_cast<const uint16_t*>(r), | 428 reinterpret_cast<const uint16_t*>(r), |
| 421 length) == 0; | 429 length) == 0; |
| 422 } | 430 } |
| 423 } | 431 } |
| 424 } | 432 } |
| 425 } // namespace internal | 433 } // namespace internal |
| 426 } // namespace v8 | 434 } // namespace v8 |
| OLD | NEW |