OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2050 template<typename Shape, typename Key> | 2050 template<typename Shape, typename Key> |
2051 int HashTable<Shape, Key>::FindEntry(Key key) { | 2051 int HashTable<Shape, Key>::FindEntry(Key key) { |
2052 return FindEntry(GetIsolate(), key); | 2052 return FindEntry(GetIsolate(), key); |
2053 } | 2053 } |
2054 | 2054 |
2055 | 2055 |
2056 // Find entry for key otherwise return kNotFound. | 2056 // Find entry for key otherwise return kNotFound. |
2057 template<typename Shape, typename Key> | 2057 template<typename Shape, typename Key> |
2058 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { | 2058 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { |
2059 uint32_t capacity = Capacity(); | 2059 uint32_t capacity = Capacity(); |
2060 uint32_t entry = FirstProbe(Shape::Hash(key), capacity); | 2060 uint32_t entry = FirstProbe(Shape::Hash(key, GetHeap()->StringHashSeed()), |
Erik Corry
2012/01/09 23:52:48
isolate->heap() is faster than GetHeap()
If the ar
| |
2061 capacity); | |
2061 uint32_t count = 1; | 2062 uint32_t count = 1; |
2062 // EnsureCapacity will guarantee the hash table is never full. | 2063 // EnsureCapacity will guarantee the hash table is never full. |
2063 while (true) { | 2064 while (true) { |
2064 Object* element = KeyAt(entry); | 2065 Object* element = KeyAt(entry); |
2065 // Empty entry. | 2066 // Empty entry. |
2066 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; | 2067 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; |
2067 if (element != isolate->heap()->raw_unchecked_the_hole_value() && | 2068 if (element != isolate->heap()->raw_unchecked_the_hole_value() && |
2068 Shape::IsMatch(key, element)) return entry; | 2069 Shape::IsMatch(key, element)) return entry; |
2069 entry = NextProbe(entry, count++, capacity); | 2070 entry = NextProbe(entry, count++, capacity); |
2070 } | 2071 } |
(...skipping 2457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4528 FixedArray::set(index+2, details.AsSmi()); | 4529 FixedArray::set(index+2, details.AsSmi()); |
4529 } | 4530 } |
4530 | 4531 |
4531 | 4532 |
4532 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { | 4533 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
4533 ASSERT(other->IsNumber()); | 4534 ASSERT(other->IsNumber()); |
4534 return key == static_cast<uint32_t>(other->Number()); | 4535 return key == static_cast<uint32_t>(other->Number()); |
4535 } | 4536 } |
4536 | 4537 |
4537 | 4538 |
4538 uint32_t NumberDictionaryShape::Hash(uint32_t key) { | 4539 uint32_t NumberDictionaryShape::Hash(uint32_t key, uint32_t seed) { |
4539 return ComputeIntegerHash(key); | 4540 return ComputeIntegerHash(key, seed); |
4540 } | 4541 } |
4541 | 4542 |
4542 | 4543 |
4543 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { | 4544 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, uint32_t seed, |
Erik Corry
2012/01/09 23:52:48
Formatting.
| |
4545 Object* other) { | |
4544 ASSERT(other->IsNumber()); | 4546 ASSERT(other->IsNumber()); |
4545 return ComputeIntegerHash(static_cast<uint32_t>(other->Number())); | 4547 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed); |
4546 } | 4548 } |
4547 | 4549 |
4548 | 4550 |
4549 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { | 4551 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
4550 return Isolate::Current()->heap()->NumberFromUint32(key); | 4552 return Isolate::Current()->heap()->NumberFromUint32(key); |
4551 } | 4553 } |
4552 | 4554 |
4553 | 4555 |
4554 bool StringDictionaryShape::IsMatch(String* key, Object* other) { | 4556 bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
4555 // We know that all entries in a hash table had their hash keys created. | 4557 // We know that all entries in a hash table had their hash keys created. |
4556 // Use that knowledge to have fast failure. | 4558 // Use that knowledge to have fast failure. |
4557 if (key->Hash() != String::cast(other)->Hash()) return false; | 4559 if (key->Hash() != String::cast(other)->Hash()) return false; |
4558 return key->Equals(String::cast(other)); | 4560 return key->Equals(String::cast(other)); |
4559 } | 4561 } |
4560 | 4562 |
4561 | 4563 |
4562 uint32_t StringDictionaryShape::Hash(String* key) { | 4564 uint32_t StringDictionaryShape::Hash(String* key, uint32_t) { |
4563 return key->Hash(); | 4565 return key->Hash(); |
4564 } | 4566 } |
4565 | 4567 |
4566 | 4568 |
4567 uint32_t StringDictionaryShape::HashForObject(String* key, Object* other) { | 4569 uint32_t StringDictionaryShape::HashForObject(String* key, uint32_t, |
Erik Corry
2012/01/09 23:52:48
Formatting.
| |
4570 Object* other) { | |
4568 return String::cast(other)->Hash(); | 4571 return String::cast(other)->Hash(); |
4569 } | 4572 } |
4570 | 4573 |
4571 | 4574 |
4572 MaybeObject* StringDictionaryShape::AsObject(String* key) { | 4575 MaybeObject* StringDictionaryShape::AsObject(String* key) { |
4573 return key; | 4576 return key; |
4574 } | 4577 } |
4575 | 4578 |
4576 | 4579 |
4577 template <int entrysize> | 4580 template <int entrysize> |
4578 bool ObjectHashTableShape<entrysize>::IsMatch(Object* key, Object* other) { | 4581 bool ObjectHashTableShape<entrysize>::IsMatch(Object* key, Object* other) { |
4579 return key->SameValue(other); | 4582 return key->SameValue(other); |
4580 } | 4583 } |
4581 | 4584 |
4582 | 4585 |
4583 template <int entrysize> | 4586 template <int entrysize> |
4584 uint32_t ObjectHashTableShape<entrysize>::Hash(Object* key) { | 4587 uint32_t ObjectHashTableShape<entrysize>::Hash(Object* key, uint32_t) { |
4585 MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); | 4588 MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); |
4586 return Smi::cast(maybe_hash->ToObjectChecked())->value(); | 4589 return Smi::cast(maybe_hash->ToObjectChecked())->value(); |
4587 } | 4590 } |
4588 | 4591 |
4589 | 4592 |
4590 template <int entrysize> | 4593 template <int entrysize> |
4591 uint32_t ObjectHashTableShape<entrysize>::HashForObject(Object* key, | 4594 uint32_t ObjectHashTableShape<entrysize>::HashForObject(Object* key, |
4595 uint32_t, | |
4592 Object* other) { | 4596 Object* other) { |
4593 MaybeObject* maybe_hash = other->GetHash(OMIT_CREATION); | 4597 MaybeObject* maybe_hash = other->GetHash(OMIT_CREATION); |
4594 return Smi::cast(maybe_hash->ToObjectChecked())->value(); | 4598 return Smi::cast(maybe_hash->ToObjectChecked())->value(); |
4595 } | 4599 } |
4596 | 4600 |
4597 | 4601 |
4598 template <int entrysize> | 4602 template <int entrysize> |
4599 MaybeObject* ObjectHashTableShape<entrysize>::AsObject(Object* key) { | 4603 MaybeObject* ObjectHashTableShape<entrysize>::AsObject(Object* key) { |
4600 return key; | 4604 return key; |
4601 } | 4605 } |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4769 #undef WRITE_INT_FIELD | 4773 #undef WRITE_INT_FIELD |
4770 #undef READ_SHORT_FIELD | 4774 #undef READ_SHORT_FIELD |
4771 #undef WRITE_SHORT_FIELD | 4775 #undef WRITE_SHORT_FIELD |
4772 #undef READ_BYTE_FIELD | 4776 #undef READ_BYTE_FIELD |
4773 #undef WRITE_BYTE_FIELD | 4777 #undef WRITE_BYTE_FIELD |
4774 | 4778 |
4775 | 4779 |
4776 } } // namespace v8::internal | 4780 } } // namespace v8::internal |
4777 | 4781 |
4778 #endif // V8_OBJECTS_INL_H_ | 4782 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |