Chromium Code Reviews| 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 6654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6665 #undef READ_INTPTR_FIELD | 6665 #undef READ_INTPTR_FIELD |
| 6666 #undef WRITE_INTPTR_FIELD | 6666 #undef WRITE_INTPTR_FIELD |
| 6667 #undef READ_UINT32_FIELD | 6667 #undef READ_UINT32_FIELD |
| 6668 #undef WRITE_UINT32_FIELD | 6668 #undef WRITE_UINT32_FIELD |
| 6669 #undef READ_SHORT_FIELD | 6669 #undef READ_SHORT_FIELD |
| 6670 #undef WRITE_SHORT_FIELD | 6670 #undef WRITE_SHORT_FIELD |
| 6671 #undef READ_BYTE_FIELD | 6671 #undef READ_BYTE_FIELD |
| 6672 #undef WRITE_BYTE_FIELD | 6672 #undef WRITE_BYTE_FIELD |
| 6673 | 6673 |
| 6674 | 6674 |
| 6675 template <typename Char> | |
| 6676 class SequentialStringKey : public HashTableKey { | |
| 6677 public: | |
| 6678 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) | |
| 6679 : string_(string), hash_field_(0), seed_(seed) { } | |
| 6680 | |
| 6681 uint32_t Hash() { | |
|
marja
2014/01/16 16:18:18
Drive-by coding style nit: don't you need to mark
ulan
2014/01/16 16:23:11
I guess we don't need to mark them as virtual. I s
| |
| 6682 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), | |
| 6683 string_.length(), | |
| 6684 seed_); | |
| 6685 | |
| 6686 uint32_t result = hash_field_ >> String::kHashShift; | |
| 6687 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | |
| 6688 return result; | |
| 6689 } | |
| 6690 | |
| 6691 | |
| 6692 uint32_t HashForObject(Object* other) { | |
| 6693 return String::cast(other)->Hash(); | |
| 6694 } | |
| 6695 | |
| 6696 Vector<const Char> string_; | |
| 6697 uint32_t hash_field_; | |
| 6698 uint32_t seed_; | |
| 6699 }; | |
| 6700 | |
| 6701 | |
| 6702 class OneByteStringKey : public SequentialStringKey<uint8_t> { | |
| 6703 public: | |
| 6704 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) | |
| 6705 : SequentialStringKey<uint8_t>(str, seed) { } | |
| 6706 | |
| 6707 bool IsMatch(Object* string) { | |
| 6708 return String::cast(string)->IsOneByteEqualTo(string_); | |
| 6709 } | |
| 6710 | |
| 6711 MaybeObject* AsObject(Heap* heap); | |
| 6712 }; | |
| 6713 | |
| 6714 | |
| 6715 class SubStringOneByteStringKey : public HashTableKey { | |
| 6716 public: | |
| 6717 explicit SubStringOneByteStringKey(Handle<SeqOneByteString> string, | |
| 6718 int from, | |
| 6719 int length) | |
| 6720 : string_(string), from_(from), length_(length) { } | |
| 6721 | |
| 6722 uint32_t Hash() { | |
| 6723 ASSERT(length_ >= 0); | |
| 6724 ASSERT(from_ + length_ <= string_->length()); | |
| 6725 uint8_t* chars = string_->GetChars() + from_; | |
| 6726 hash_field_ = StringHasher::HashSequentialString( | |
| 6727 chars, length_, string_->GetHeap()->HashSeed()); | |
| 6728 uint32_t result = hash_field_ >> String::kHashShift; | |
| 6729 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | |
| 6730 return result; | |
| 6731 } | |
| 6732 | |
| 6733 | |
| 6734 uint32_t HashForObject(Object* other) { | |
| 6735 return String::cast(other)->Hash(); | |
| 6736 } | |
| 6737 | |
| 6738 bool IsMatch(Object* string) { | |
| 6739 Vector<const uint8_t> chars(string_->GetChars() + from_, length_); | |
| 6740 return String::cast(string)->IsOneByteEqualTo(chars); | |
| 6741 } | |
| 6742 | |
| 6743 MaybeObject* AsObject(Heap* heap); | |
| 6744 | |
| 6745 private: | |
| 6746 Handle<SeqOneByteString> string_; | |
| 6747 int from_; | |
| 6748 int length_; | |
| 6749 uint32_t hash_field_; | |
| 6750 }; | |
| 6751 | |
| 6752 | |
| 6753 class TwoByteStringKey : public SequentialStringKey<uc16> { | |
| 6754 public: | |
| 6755 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | |
| 6756 : SequentialStringKey<uc16>(str, seed) { } | |
| 6757 | |
| 6758 bool IsMatch(Object* string) { | |
| 6759 return String::cast(string)->IsTwoByteEqualTo(string_); | |
| 6760 } | |
| 6761 | |
| 6762 MaybeObject* AsObject(Heap* heap); | |
| 6763 }; | |
| 6764 | |
| 6765 | |
| 6766 // Utf8StringKey carries a vector of chars as key. | |
| 6767 class Utf8StringKey : public HashTableKey { | |
| 6768 public: | |
| 6769 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) | |
| 6770 : string_(string), hash_field_(0), seed_(seed) { } | |
| 6771 | |
| 6772 bool IsMatch(Object* string) { | |
| 6773 return String::cast(string)->IsUtf8EqualTo(string_); | |
| 6774 } | |
| 6775 | |
| 6776 uint32_t Hash() { | |
| 6777 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | |
| 6778 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | |
| 6779 uint32_t result = hash_field_ >> String::kHashShift; | |
| 6780 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | |
| 6781 return result; | |
| 6782 } | |
| 6783 | |
| 6784 uint32_t HashForObject(Object* other) { | |
| 6785 return String::cast(other)->Hash(); | |
| 6786 } | |
| 6787 | |
| 6788 MaybeObject* AsObject(Heap* heap) { | |
| 6789 if (hash_field_ == 0) Hash(); | |
| 6790 return heap->AllocateInternalizedStringFromUtf8(string_, | |
| 6791 chars_, | |
| 6792 hash_field_); | |
| 6793 } | |
| 6794 | |
| 6795 Vector<const char> string_; | |
| 6796 uint32_t hash_field_; | |
| 6797 int chars_; // Caches the number of characters when computing the hash code. | |
| 6798 uint32_t seed_; | |
| 6799 }; | |
| 6800 | |
| 6801 | |
| 6675 } } // namespace v8::internal | 6802 } } // namespace v8::internal |
| 6676 | 6803 |
| 6677 #endif // V8_OBJECTS_INL_H_ | 6804 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |