Chromium Code Reviews| Index: src/objects-inl.h |
| diff --git a/src/objects-inl.h b/src/objects-inl.h |
| index 7bd8d59801f249183ea5b4e454af576d07cf4734..340aa8b9866c81c97c930ce052315f2cbf6461db 100644 |
| --- a/src/objects-inl.h |
| +++ b/src/objects-inl.h |
| @@ -6672,6 +6672,133 @@ void FlexibleBodyDescriptor<start_offset>::IterateBody(HeapObject* obj, |
| #undef WRITE_BYTE_FIELD |
| +template <typename Char> |
| +class SequentialStringKey : public HashTableKey { |
| + public: |
| + explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) |
| + : string_(string), hash_field_(0), seed_(seed) { } |
| + |
| + 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
|
| + hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), |
| + string_.length(), |
| + seed_); |
| + |
| + uint32_t result = hash_field_ >> String::kHashShift; |
| + ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| + return result; |
| + } |
| + |
| + |
| + uint32_t HashForObject(Object* other) { |
| + return String::cast(other)->Hash(); |
| + } |
| + |
| + Vector<const Char> string_; |
| + uint32_t hash_field_; |
| + uint32_t seed_; |
| +}; |
| + |
| + |
| +class OneByteStringKey : public SequentialStringKey<uint8_t> { |
| + public: |
| + OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |
| + : SequentialStringKey<uint8_t>(str, seed) { } |
| + |
| + bool IsMatch(Object* string) { |
| + return String::cast(string)->IsOneByteEqualTo(string_); |
| + } |
| + |
| + MaybeObject* AsObject(Heap* heap); |
| +}; |
| + |
| + |
| +class SubStringOneByteStringKey : public HashTableKey { |
| + public: |
| + explicit SubStringOneByteStringKey(Handle<SeqOneByteString> string, |
| + int from, |
| + int length) |
| + : string_(string), from_(from), length_(length) { } |
| + |
| + uint32_t Hash() { |
| + ASSERT(length_ >= 0); |
| + ASSERT(from_ + length_ <= string_->length()); |
| + uint8_t* chars = string_->GetChars() + from_; |
| + hash_field_ = StringHasher::HashSequentialString( |
| + chars, length_, string_->GetHeap()->HashSeed()); |
| + uint32_t result = hash_field_ >> String::kHashShift; |
| + ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| + return result; |
| + } |
| + |
| + |
| + uint32_t HashForObject(Object* other) { |
| + return String::cast(other)->Hash(); |
| + } |
| + |
| + bool IsMatch(Object* string) { |
| + Vector<const uint8_t> chars(string_->GetChars() + from_, length_); |
| + return String::cast(string)->IsOneByteEqualTo(chars); |
| + } |
| + |
| + MaybeObject* AsObject(Heap* heap); |
| + |
| + private: |
| + Handle<SeqOneByteString> string_; |
| + int from_; |
| + int length_; |
| + uint32_t hash_field_; |
| +}; |
| + |
| + |
| +class TwoByteStringKey : public SequentialStringKey<uc16> { |
| + public: |
| + explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
| + : SequentialStringKey<uc16>(str, seed) { } |
| + |
| + bool IsMatch(Object* string) { |
| + return String::cast(string)->IsTwoByteEqualTo(string_); |
| + } |
| + |
| + MaybeObject* AsObject(Heap* heap); |
| +}; |
| + |
| + |
| +// Utf8StringKey carries a vector of chars as key. |
| +class Utf8StringKey : public HashTableKey { |
| + public: |
| + explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |
| + : string_(string), hash_field_(0), seed_(seed) { } |
| + |
| + bool IsMatch(Object* string) { |
| + return String::cast(string)->IsUtf8EqualTo(string_); |
| + } |
| + |
| + uint32_t Hash() { |
| + if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
| + hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
| + uint32_t result = hash_field_ >> String::kHashShift; |
| + ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| + return result; |
| + } |
| + |
| + uint32_t HashForObject(Object* other) { |
| + return String::cast(other)->Hash(); |
| + } |
| + |
| + MaybeObject* AsObject(Heap* heap) { |
| + if (hash_field_ == 0) Hash(); |
| + return heap->AllocateInternalizedStringFromUtf8(string_, |
| + chars_, |
| + hash_field_); |
| + } |
| + |
| + Vector<const char> string_; |
| + uint32_t hash_field_; |
| + int chars_; // Caches the number of characters when computing the hash code. |
| + uint32_t seed_; |
| +}; |
| + |
| + |
| } } // namespace v8::internal |
| #endif // V8_OBJECTS_INL_H_ |