OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 HashTableKey* key) { | 510 HashTableKey* key) { |
511 return key->AsHandle(isolate); | 511 return key->AsHandle(isolate); |
512 } | 512 } |
513 | 513 |
514 template <typename Char> | 514 template <typename Char> |
515 class SequentialStringKey : public HashTableKey { | 515 class SequentialStringKey : public HashTableKey { |
516 public: | 516 public: |
517 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) | 517 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) |
518 : string_(string), hash_field_(0), seed_(seed) { } | 518 : string_(string), hash_field_(0), seed_(seed) { } |
519 | 519 |
520 virtual uint32_t Hash() OVERRIDE { | 520 uint32_t Hash() OVERRIDE { |
521 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), | 521 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), |
522 string_.length(), | 522 string_.length(), |
523 seed_); | 523 seed_); |
524 | 524 |
525 uint32_t result = hash_field_ >> String::kHashShift; | 525 uint32_t result = hash_field_ >> String::kHashShift; |
526 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 526 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
527 return result; | 527 return result; |
528 } | 528 } |
529 | 529 |
530 | 530 |
531 virtual uint32_t HashForObject(Object* other) OVERRIDE { | 531 uint32_t HashForObject(Object* other) OVERRIDE { |
532 return String::cast(other)->Hash(); | 532 return String::cast(other)->Hash(); |
533 } | 533 } |
534 | 534 |
535 Vector<const Char> string_; | 535 Vector<const Char> string_; |
536 uint32_t hash_field_; | 536 uint32_t hash_field_; |
537 uint32_t seed_; | 537 uint32_t seed_; |
538 }; | 538 }; |
539 | 539 |
540 | 540 |
541 class OneByteStringKey : public SequentialStringKey<uint8_t> { | 541 class OneByteStringKey : public SequentialStringKey<uint8_t> { |
542 public: | 542 public: |
543 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) | 543 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |
544 : SequentialStringKey<uint8_t>(str, seed) { } | 544 : SequentialStringKey<uint8_t>(str, seed) { } |
545 | 545 |
546 virtual bool IsMatch(Object* string) OVERRIDE { | 546 bool IsMatch(Object* string) OVERRIDE { |
547 return String::cast(string)->IsOneByteEqualTo(string_); | 547 return String::cast(string)->IsOneByteEqualTo(string_); |
548 } | 548 } |
549 | 549 |
550 virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 550 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; |
551 }; | 551 }; |
552 | 552 |
553 | 553 |
554 class SeqOneByteSubStringKey : public HashTableKey { | 554 class SeqOneByteSubStringKey : public HashTableKey { |
555 public: | 555 public: |
556 SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) | 556 SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) |
557 : string_(string), from_(from), length_(length) { | 557 : string_(string), from_(from), length_(length) { |
558 DCHECK(string_->IsSeqOneByteString()); | 558 DCHECK(string_->IsSeqOneByteString()); |
559 } | 559 } |
560 | 560 |
561 virtual uint32_t Hash() OVERRIDE { | 561 uint32_t Hash() OVERRIDE { |
562 DCHECK(length_ >= 0); | 562 DCHECK(length_ >= 0); |
563 DCHECK(from_ + length_ <= string_->length()); | 563 DCHECK(from_ + length_ <= string_->length()); |
564 const uint8_t* chars = string_->GetChars() + from_; | 564 const uint8_t* chars = string_->GetChars() + from_; |
565 hash_field_ = StringHasher::HashSequentialString( | 565 hash_field_ = StringHasher::HashSequentialString( |
566 chars, length_, string_->GetHeap()->HashSeed()); | 566 chars, length_, string_->GetHeap()->HashSeed()); |
567 uint32_t result = hash_field_ >> String::kHashShift; | 567 uint32_t result = hash_field_ >> String::kHashShift; |
568 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 568 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
569 return result; | 569 return result; |
570 } | 570 } |
571 | 571 |
572 virtual uint32_t HashForObject(Object* other) OVERRIDE { | 572 uint32_t HashForObject(Object* other) OVERRIDE { |
573 return String::cast(other)->Hash(); | 573 return String::cast(other)->Hash(); |
574 } | 574 } |
575 | 575 |
576 virtual bool IsMatch(Object* string) OVERRIDE; | 576 bool IsMatch(Object* string) OVERRIDE; |
577 virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 577 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; |
578 | 578 |
579 private: | 579 private: |
580 Handle<SeqOneByteString> string_; | 580 Handle<SeqOneByteString> string_; |
581 int from_; | 581 int from_; |
582 int length_; | 582 int length_; |
583 uint32_t hash_field_; | 583 uint32_t hash_field_; |
584 }; | 584 }; |
585 | 585 |
586 | 586 |
587 class TwoByteStringKey : public SequentialStringKey<uc16> { | 587 class TwoByteStringKey : public SequentialStringKey<uc16> { |
588 public: | 588 public: |
589 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 589 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
590 : SequentialStringKey<uc16>(str, seed) { } | 590 : SequentialStringKey<uc16>(str, seed) { } |
591 | 591 |
592 virtual bool IsMatch(Object* string) OVERRIDE { | 592 bool IsMatch(Object* string) OVERRIDE { |
593 return String::cast(string)->IsTwoByteEqualTo(string_); | 593 return String::cast(string)->IsTwoByteEqualTo(string_); |
594 } | 594 } |
595 | 595 |
596 virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 596 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; |
597 }; | 597 }; |
598 | 598 |
599 | 599 |
600 // Utf8StringKey carries a vector of chars as key. | 600 // Utf8StringKey carries a vector of chars as key. |
601 class Utf8StringKey : public HashTableKey { | 601 class Utf8StringKey : public HashTableKey { |
602 public: | 602 public: |
603 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) | 603 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |
604 : string_(string), hash_field_(0), seed_(seed) { } | 604 : string_(string), hash_field_(0), seed_(seed) { } |
605 | 605 |
606 virtual bool IsMatch(Object* string) OVERRIDE { | 606 bool IsMatch(Object* string) OVERRIDE { |
607 return String::cast(string)->IsUtf8EqualTo(string_); | 607 return String::cast(string)->IsUtf8EqualTo(string_); |
608 } | 608 } |
609 | 609 |
610 virtual uint32_t Hash() OVERRIDE { | 610 uint32_t Hash() OVERRIDE { |
611 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | 611 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
612 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | 612 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
613 uint32_t result = hash_field_ >> String::kHashShift; | 613 uint32_t result = hash_field_ >> String::kHashShift; |
614 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 614 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
615 return result; | 615 return result; |
616 } | 616 } |
617 | 617 |
618 virtual uint32_t HashForObject(Object* other) OVERRIDE { | 618 uint32_t HashForObject(Object* other) OVERRIDE { |
619 return String::cast(other)->Hash(); | 619 return String::cast(other)->Hash(); |
620 } | 620 } |
621 | 621 |
622 virtual Handle<Object> AsHandle(Isolate* isolate) OVERRIDE { | 622 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE { |
623 if (hash_field_ == 0) Hash(); | 623 if (hash_field_ == 0) Hash(); |
624 return isolate->factory()->NewInternalizedStringFromUtf8( | 624 return isolate->factory()->NewInternalizedStringFromUtf8( |
625 string_, chars_, hash_field_); | 625 string_, chars_, hash_field_); |
626 } | 626 } |
627 | 627 |
628 Vector<const char> string_; | 628 Vector<const char> string_; |
629 uint32_t hash_field_; | 629 uint32_t hash_field_; |
630 int chars_; // Caches the number of characters when computing the hash code. | 630 int chars_; // Caches the number of characters when computing the hash code. |
631 uint32_t seed_; | 631 uint32_t seed_; |
632 }; | 632 }; |
(...skipping 6885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7518 #undef READ_SHORT_FIELD | 7518 #undef READ_SHORT_FIELD |
7519 #undef WRITE_SHORT_FIELD | 7519 #undef WRITE_SHORT_FIELD |
7520 #undef READ_BYTE_FIELD | 7520 #undef READ_BYTE_FIELD |
7521 #undef WRITE_BYTE_FIELD | 7521 #undef WRITE_BYTE_FIELD |
7522 #undef NOBARRIER_READ_BYTE_FIELD | 7522 #undef NOBARRIER_READ_BYTE_FIELD |
7523 #undef NOBARRIER_WRITE_BYTE_FIELD | 7523 #undef NOBARRIER_WRITE_BYTE_FIELD |
7524 | 7524 |
7525 } } // namespace v8::internal | 7525 } } // namespace v8::internal |
7526 | 7526 |
7527 #endif // V8_OBJECTS_INL_H_ | 7527 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |