| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 11745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11756 value <<= String::ArrayIndexValueBits::kShift; | 11756 value <<= String::ArrayIndexValueBits::kShift; |
| 11757 value |= length << String::ArrayIndexLengthBits::kShift; | 11757 value |= length << String::ArrayIndexLengthBits::kShift; |
| 11758 | 11758 |
| 11759 DCHECK((value & String::kIsNotArrayIndexMask) == 0); | 11759 DCHECK((value & String::kIsNotArrayIndexMask) == 0); |
| 11760 DCHECK_EQ(length <= String::kMaxCachedArrayIndexLength, | 11760 DCHECK_EQ(length <= String::kMaxCachedArrayIndexLength, |
| 11761 (value & String::kContainsCachedArrayIndexMask) == 0); | 11761 (value & String::kContainsCachedArrayIndexMask) == 0); |
| 11762 return value; | 11762 return value; |
| 11763 } | 11763 } |
| 11764 | 11764 |
| 11765 | 11765 |
| 11766 uint32_t StringHasher::GetHashField() { | |
| 11767 if (length_ <= String::kMaxHashCalcLength) { | |
| 11768 if (is_array_index_) { | |
| 11769 return MakeArrayIndexHash(array_index_, length_); | |
| 11770 } | |
| 11771 return (GetHashCore(raw_running_hash_) << String::kHashShift) | | |
| 11772 String::kIsNotArrayIndexMask; | |
| 11773 } else { | |
| 11774 return (length_ << String::kHashShift) | String::kIsNotArrayIndexMask; | |
| 11775 } | |
| 11776 } | |
| 11777 | |
| 11778 | |
| 11779 uint32_t StringHasher::ComputeUtf8Hash(Vector<const char> chars, | 11766 uint32_t StringHasher::ComputeUtf8Hash(Vector<const char> chars, |
| 11780 uint32_t seed, | 11767 uint32_t seed, |
| 11781 int* utf16_length_out) { | 11768 int* utf16_length_out) { |
| 11782 int vector_length = chars.length(); | 11769 int vector_length = chars.length(); |
| 11783 // Handle some edge cases | 11770 // Handle some edge cases |
| 11784 if (vector_length <= 1) { | 11771 if (vector_length <= 1) { |
| 11785 DCHECK(vector_length == 0 || | 11772 DCHECK(vector_length == 0 || |
| 11786 static_cast<uint8_t>(chars.start()[0]) <= | 11773 static_cast<uint8_t>(chars.start()[0]) <= |
| 11787 unibrow::Utf8::kMaxOneByteChar); | 11774 unibrow::Utf8::kMaxOneByteChar); |
| 11788 *utf16_length_out = vector_length; | 11775 *utf16_length_out = vector_length; |
| (...skipping 5615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17404 : isolate->factory()->cons_string_map(); | 17391 : isolate->factory()->cons_string_map(); |
| 17405 string->set_map(*map); | 17392 string->set_map(*map); |
| 17406 Handle<ConsString> cons = Handle<ConsString>::cast(string); | 17393 Handle<ConsString> cons = Handle<ConsString>::cast(string); |
| 17407 cons->set_first(*result); | 17394 cons->set_first(*result); |
| 17408 cons->set_second(isolate->heap()->empty_string()); | 17395 cons->set_second(isolate->heap()->empty_string()); |
| 17409 } | 17396 } |
| 17410 } | 17397 } |
| 17411 return result; | 17398 return result; |
| 17412 } | 17399 } |
| 17413 | 17400 |
| 17414 | 17401 Handle<String> StringTable::InsertKey(Isolate* isolate, |
| 17415 Handle<String> StringTable::LookupKey(Isolate* isolate, HashTableKey* key) { | 17402 Handle<StringTable> table, |
| 17416 Handle<StringTable> table = isolate->factory()->string_table(); | 17403 HashTableKey* key, int32_t hash) { |
| 17417 int entry = table->FindEntry(key); | |
| 17418 | |
| 17419 // String already in table. | |
| 17420 if (entry != kNotFound) { | |
| 17421 return handle(String::cast(table->KeyAt(entry)), isolate); | |
| 17422 } | |
| 17423 | |
| 17424 // Adding new string. Grow table if needed. | 17404 // Adding new string. Grow table if needed. |
| 17425 table = StringTable::EnsureCapacity(table, 1, key); | 17405 table = StringTable::EnsureCapacity(table, 1, key); |
| 17426 | 17406 |
| 17427 // Create string object. | 17407 // Create string object. |
| 17428 Handle<Object> string = key->AsHandle(isolate); | 17408 Handle<Object> string = key->AsHandle(isolate); |
| 17429 // There must be no attempts to internalize strings that could throw | 17409 // There must be no attempts to internalize strings that could throw |
| 17430 // InvalidStringLength error. | 17410 // InvalidStringLength error. |
| 17431 CHECK(!string.is_null()); | 17411 CHECK(!string.is_null()); |
| 17432 | 17412 |
| 17433 // Add the new string and return it along with the string table. | 17413 // Add the new string and return it along with the string table. |
| 17434 entry = table->FindInsertionEntry(key->Hash()); | 17414 int entry = table->FindInsertionEntry(hash); |
| 17435 table->set(EntryToIndex(entry), *string); | 17415 table->set(EntryToIndex(entry), *string); |
| 17436 table->ElementAdded(); | 17416 table->ElementAdded(); |
| 17437 | 17417 |
| 17438 isolate->heap()->SetRootStringTable(*table); | 17418 isolate->heap()->SetRootStringTable(*table); |
| 17439 return Handle<String>::cast(string); | 17419 return Handle<String>::cast(string); |
| 17440 } | 17420 } |
| 17441 | 17421 |
| 17442 | 17422 |
| 17443 String* StringTable::LookupKeyIfExists(Isolate* isolate, HashTableKey* key) { | 17423 String* StringTable::LookupKeyIfExists(Isolate* isolate, HashTableKey* key) { |
| 17444 Handle<StringTable> table = isolate->factory()->string_table(); | 17424 Handle<StringTable> table = isolate->factory()->string_table(); |
| (...skipping 2851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20296 // depend on this. | 20276 // depend on this. |
| 20297 return DICTIONARY_ELEMENTS; | 20277 return DICTIONARY_ELEMENTS; |
| 20298 } | 20278 } |
| 20299 DCHECK_LE(kind, LAST_ELEMENTS_KIND); | 20279 DCHECK_LE(kind, LAST_ELEMENTS_KIND); |
| 20300 return kind; | 20280 return kind; |
| 20301 } | 20281 } |
| 20302 } | 20282 } |
| 20303 | 20283 |
| 20304 } // namespace internal | 20284 } // namespace internal |
| 20305 } // namespace v8 | 20285 } // namespace v8 |
| OLD | NEW |