| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 uc32 FlatStringReader::Get(int index) { | 463 uc32 FlatStringReader::Get(int index) { |
| 464 ASSERT(0 <= index && index <= length_); | 464 ASSERT(0 <= index && index <= length_); |
| 465 if (is_ascii_) { | 465 if (is_ascii_) { |
| 466 return static_cast<const byte*>(start_)[index]; | 466 return static_cast<const byte*>(start_)[index]; |
| 467 } else { | 467 } else { |
| 468 return static_cast<const uc16*>(start_)[index]; | 468 return static_cast<const uc16*>(start_)[index]; |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 | 472 |
| 473 Handle<Object> HashTableKey::AsHandle(Isolate* isolate) { |
| 474 CALL_HEAP_FUNCTION(isolate, AsObject(isolate->heap()), Object); |
| 475 } |
| 476 |
| 477 |
| 473 template <typename Char> | 478 template <typename Char> |
| 474 class SequentialStringKey : public HashTableKey { | 479 class SequentialStringKey : public HashTableKey { |
| 475 public: | 480 public: |
| 476 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) | 481 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) |
| 477 : string_(string), hash_field_(0), seed_(seed) { } | 482 : string_(string), hash_field_(0), seed_(seed) { } |
| 478 | 483 |
| 479 virtual uint32_t Hash() { | 484 virtual uint32_t Hash() V8_OVERRIDE { |
| 480 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), | 485 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), |
| 481 string_.length(), | 486 string_.length(), |
| 482 seed_); | 487 seed_); |
| 483 | 488 |
| 484 uint32_t result = hash_field_ >> String::kHashShift; | 489 uint32_t result = hash_field_ >> String::kHashShift; |
| 485 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 490 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 486 return result; | 491 return result; |
| 487 } | 492 } |
| 488 | 493 |
| 489 | 494 |
| 490 virtual uint32_t HashForObject(Object* other) { | 495 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
| 491 return String::cast(other)->Hash(); | 496 return String::cast(other)->Hash(); |
| 492 } | 497 } |
| 493 | 498 |
| 494 Vector<const Char> string_; | 499 Vector<const Char> string_; |
| 495 uint32_t hash_field_; | 500 uint32_t hash_field_; |
| 496 uint32_t seed_; | 501 uint32_t seed_; |
| 497 }; | 502 }; |
| 498 | 503 |
| 499 | 504 |
| 500 class OneByteStringKey : public SequentialStringKey<uint8_t> { | 505 class OneByteStringKey : public SequentialStringKey<uint8_t> { |
| 501 public: | 506 public: |
| 502 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) | 507 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |
| 503 : SequentialStringKey<uint8_t>(str, seed) { } | 508 : SequentialStringKey<uint8_t>(str, seed) { } |
| 504 | 509 |
| 505 virtual bool IsMatch(Object* string) { | 510 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
| 506 return String::cast(string)->IsOneByteEqualTo(string_); | 511 return String::cast(string)->IsOneByteEqualTo(string_); |
| 507 } | 512 } |
| 508 | 513 |
| 509 virtual MaybeObject* AsObject(Heap* heap); | 514 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE; |
| 510 }; | 515 }; |
| 511 | 516 |
| 512 | 517 |
| 513 template<class Char> | 518 template<class Char> |
| 514 class SubStringKey : public HashTableKey { | 519 class SubStringKey : public HashTableKey { |
| 515 public: | 520 public: |
| 516 SubStringKey(Handle<String> string, int from, int length) | 521 SubStringKey(Handle<String> string, int from, int length) |
| 517 : string_(string), from_(from), length_(length) { | 522 : string_(string), from_(from), length_(length) { |
| 518 if (string_->IsSlicedString()) { | 523 if (string_->IsSlicedString()) { |
| 519 string_ = Handle<String>(Unslice(*string_, &from_)); | 524 string_ = Handle<String>(Unslice(*string_, &from_)); |
| 520 } | 525 } |
| 521 ASSERT(string_->IsSeqString() || string->IsExternalString()); | 526 ASSERT(string_->IsSeqString() || string->IsExternalString()); |
| 522 } | 527 } |
| 523 | 528 |
| 524 virtual uint32_t Hash() { | 529 virtual uint32_t Hash() V8_OVERRIDE { |
| 525 ASSERT(length_ >= 0); | 530 ASSERT(length_ >= 0); |
| 526 ASSERT(from_ + length_ <= string_->length()); | 531 ASSERT(from_ + length_ <= string_->length()); |
| 527 const Char* chars = GetChars() + from_; | 532 const Char* chars = GetChars() + from_; |
| 528 hash_field_ = StringHasher::HashSequentialString( | 533 hash_field_ = StringHasher::HashSequentialString( |
| 529 chars, length_, string_->GetHeap()->HashSeed()); | 534 chars, length_, string_->GetHeap()->HashSeed()); |
| 530 uint32_t result = hash_field_ >> String::kHashShift; | 535 uint32_t result = hash_field_ >> String::kHashShift; |
| 531 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 536 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 532 return result; | 537 return result; |
| 533 } | 538 } |
| 534 | 539 |
| 535 virtual uint32_t HashForObject(Object* other) { | 540 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
| 536 return String::cast(other)->Hash(); | 541 return String::cast(other)->Hash(); |
| 537 } | 542 } |
| 538 | 543 |
| 539 virtual bool IsMatch(Object* string); | 544 virtual bool IsMatch(Object* string) V8_OVERRIDE; |
| 540 virtual MaybeObject* AsObject(Heap* heap); | 545 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE; |
| 541 | 546 |
| 542 private: | 547 private: |
| 543 const Char* GetChars(); | 548 const Char* GetChars(); |
| 544 String* Unslice(String* string, int* offset) { | 549 String* Unslice(String* string, int* offset) { |
| 545 while (string->IsSlicedString()) { | 550 while (string->IsSlicedString()) { |
| 546 SlicedString* sliced = SlicedString::cast(string); | 551 SlicedString* sliced = SlicedString::cast(string); |
| 547 *offset += sliced->offset(); | 552 *offset += sliced->offset(); |
| 548 string = sliced->parent(); | 553 string = sliced->parent(); |
| 549 } | 554 } |
| 550 return string; | 555 return string; |
| 551 } | 556 } |
| 552 | 557 |
| 553 Handle<String> string_; | 558 Handle<String> string_; |
| 554 int from_; | 559 int from_; |
| 555 int length_; | 560 int length_; |
| 556 uint32_t hash_field_; | 561 uint32_t hash_field_; |
| 557 }; | 562 }; |
| 558 | 563 |
| 559 | 564 |
| 560 class TwoByteStringKey : public SequentialStringKey<uc16> { | 565 class TwoByteStringKey : public SequentialStringKey<uc16> { |
| 561 public: | 566 public: |
| 562 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 567 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
| 563 : SequentialStringKey<uc16>(str, seed) { } | 568 : SequentialStringKey<uc16>(str, seed) { } |
| 564 | 569 |
| 565 virtual bool IsMatch(Object* string) { | 570 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
| 566 return String::cast(string)->IsTwoByteEqualTo(string_); | 571 return String::cast(string)->IsTwoByteEqualTo(string_); |
| 567 } | 572 } |
| 568 | 573 |
| 569 virtual MaybeObject* AsObject(Heap* heap); | 574 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE; |
| 570 }; | 575 }; |
| 571 | 576 |
| 572 | 577 |
| 573 // Utf8StringKey carries a vector of chars as key. | 578 // Utf8StringKey carries a vector of chars as key. |
| 574 class Utf8StringKey : public HashTableKey { | 579 class Utf8StringKey : public HashTableKey { |
| 575 public: | 580 public: |
| 576 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) | 581 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |
| 577 : string_(string), hash_field_(0), seed_(seed) { } | 582 : string_(string), hash_field_(0), seed_(seed) { } |
| 578 | 583 |
| 579 virtual bool IsMatch(Object* string) { | 584 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
| 580 return String::cast(string)->IsUtf8EqualTo(string_); | 585 return String::cast(string)->IsUtf8EqualTo(string_); |
| 581 } | 586 } |
| 582 | 587 |
| 583 virtual uint32_t Hash() { | 588 virtual uint32_t Hash() V8_OVERRIDE { |
| 584 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | 589 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
| 585 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | 590 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
| 586 uint32_t result = hash_field_ >> String::kHashShift; | 591 uint32_t result = hash_field_ >> String::kHashShift; |
| 587 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 592 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 588 return result; | 593 return result; |
| 589 } | 594 } |
| 590 | 595 |
| 591 virtual uint32_t HashForObject(Object* other) { | 596 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
| 592 return String::cast(other)->Hash(); | 597 return String::cast(other)->Hash(); |
| 593 } | 598 } |
| 594 | 599 |
| 595 virtual MaybeObject* AsObject(Heap* heap) { | 600 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE { |
| 596 if (hash_field_ == 0) Hash(); | 601 if (hash_field_ == 0) Hash(); |
| 597 return heap->AllocateInternalizedStringFromUtf8(string_, | 602 return heap->AllocateInternalizedStringFromUtf8(string_, |
| 598 chars_, | 603 chars_, |
| 599 hash_field_); | 604 hash_field_); |
| 600 } | 605 } |
| 601 | 606 |
| 602 Vector<const char> string_; | 607 Vector<const char> string_; |
| 603 uint32_t hash_field_; | 608 uint32_t hash_field_; |
| 604 int chars_; // Caches the number of characters when computing the hash code. | 609 int chars_; // Caches the number of characters when computing the hash code. |
| 605 uint32_t seed_; | 610 uint32_t seed_; |
| (...skipping 6414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7020 #undef READ_SHORT_FIELD | 7025 #undef READ_SHORT_FIELD |
| 7021 #undef WRITE_SHORT_FIELD | 7026 #undef WRITE_SHORT_FIELD |
| 7022 #undef READ_BYTE_FIELD | 7027 #undef READ_BYTE_FIELD |
| 7023 #undef WRITE_BYTE_FIELD | 7028 #undef WRITE_BYTE_FIELD |
| 7024 #undef NOBARRIER_READ_BYTE_FIELD | 7029 #undef NOBARRIER_READ_BYTE_FIELD |
| 7025 #undef NOBARRIER_WRITE_BYTE_FIELD | 7030 #undef NOBARRIER_WRITE_BYTE_FIELD |
| 7026 | 7031 |
| 7027 } } // namespace v8::internal | 7032 } } // namespace v8::internal |
| 7028 | 7033 |
| 7029 #endif // V8_OBJECTS_INL_H_ | 7034 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |