| 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 356 |
| 357 #undef GENERATE_VALUE_GETTER | 357 #undef GENERATE_VALUE_GETTER |
| 358 | 358 |
| 359 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, | 359 AstRawString* AstValueFactory::GetString(uint32_t hash, bool is_one_byte, |
| 360 Vector<const byte> literal_bytes) { | 360 Vector<const byte> literal_bytes) { |
| 361 // literal_bytes here points to whatever the user passed, and this is OK | 361 // literal_bytes here points to whatever the user passed, and this is OK |
| 362 // because we use vector_compare (which checks the contents) to compare | 362 // because we use vector_compare (which checks the contents) to compare |
| 363 // against the AstRawStrings which are in the string_table_. We should not | 363 // against the AstRawStrings which are in the string_table_. We should not |
| 364 // return this AstRawString. | 364 // return this AstRawString. |
| 365 AstRawString key(is_one_byte, literal_bytes, hash); | 365 AstRawString key(is_one_byte, literal_bytes, hash); |
| 366 HashMap::Entry* entry = string_table_.Lookup(&key, hash, true); | 366 HashMap::Entry* entry = string_table_.LookupOrInsert(&key, hash); |
| 367 if (entry->value == NULL) { | 367 if (entry->value == NULL) { |
| 368 // Copy literal contents for later comparison. | 368 // Copy literal contents for later comparison. |
| 369 int length = literal_bytes.length(); | 369 int length = literal_bytes.length(); |
| 370 byte* new_literal_bytes = zone_->NewArray<byte>(length); | 370 byte* new_literal_bytes = zone_->NewArray<byte>(length); |
| 371 memcpy(new_literal_bytes, literal_bytes.start(), length); | 371 memcpy(new_literal_bytes, literal_bytes.start(), length); |
| 372 AstRawString* new_string = new (zone_) AstRawString( | 372 AstRawString* new_string = new (zone_) AstRawString( |
| 373 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); | 373 is_one_byte, Vector<const byte>(new_literal_bytes, length), hash); |
| 374 entry->key = new_string; | 374 entry->key = new_string; |
| 375 strings_.Add(new_string); | 375 strings_.Add(new_string); |
| 376 if (isolate_) { | 376 if (isolate_) { |
| 377 new_string->Internalize(isolate_); | 377 new_string->Internalize(isolate_); |
| 378 } | 378 } |
| 379 entry->value = reinterpret_cast<void*>(1); | 379 entry->value = reinterpret_cast<void*>(1); |
| 380 } | 380 } |
| 381 return reinterpret_cast<AstRawString*>(entry->key); | 381 return reinterpret_cast<AstRawString*>(entry->key); |
| 382 } | 382 } |
| 383 | 383 |
| 384 | 384 |
| 385 } } // namespace v8::internal | 385 } } // namespace v8::internal |
| OLD | NEW |