Chromium Code Reviews| 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( |
| 2061 HashTable<Shape, Key>::Hash(key), | |
|
Erik Corry
2012/01/10 07:29:28
This all fits on one line.
| |
| 2062 capacity | |
| 2063 ); | |
| 2061 uint32_t count = 1; | 2064 uint32_t count = 1; |
| 2062 // EnsureCapacity will guarantee the hash table is never full. | 2065 // EnsureCapacity will guarantee the hash table is never full. |
| 2063 while (true) { | 2066 while (true) { |
| 2064 Object* element = KeyAt(entry); | 2067 Object* element = KeyAt(entry); |
| 2065 // Empty entry. | 2068 // Empty entry. |
| 2066 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; | 2069 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; |
| 2067 if (element != isolate->heap()->raw_unchecked_the_hole_value() && | 2070 if (element != isolate->heap()->raw_unchecked_the_hole_value() && |
| 2068 Shape::IsMatch(key, element)) return entry; | 2071 Shape::IsMatch(key, element)) return entry; |
| 2069 entry = NextProbe(entry, count++, capacity); | 2072 entry = NextProbe(entry, count++, capacity); |
| 2070 } | 2073 } |
| (...skipping 2458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4529 } | 4532 } |
| 4530 | 4533 |
| 4531 | 4534 |
| 4532 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { | 4535 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
| 4533 ASSERT(other->IsNumber()); | 4536 ASSERT(other->IsNumber()); |
| 4534 return key == static_cast<uint32_t>(other->Number()); | 4537 return key == static_cast<uint32_t>(other->Number()); |
| 4535 } | 4538 } |
| 4536 | 4539 |
| 4537 | 4540 |
| 4538 uint32_t NumberDictionaryShape::Hash(uint32_t key) { | 4541 uint32_t NumberDictionaryShape::Hash(uint32_t key) { |
| 4539 return ComputeIntegerHash(key); | 4542 return SeededHash(key, 0); |
|
Erik Corry
2012/01/10 07:29:28
I would appreciate a comment as to why the seed is
| |
| 4540 } | 4543 } |
| 4541 | 4544 |
| 4542 | 4545 |
| 4543 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { | 4546 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { |
| 4544 ASSERT(other->IsNumber()); | 4547 return SeededHashForObject(key, 0, other); |
| 4545 return ComputeIntegerHash(static_cast<uint32_t>(other->Number())); | |
| 4546 } | 4548 } |
| 4547 | 4549 |
| 4550 uint32_t NumberDictionaryShape::SeededHash(uint32_t key, uint32_t seed) { | |
| 4551 return ComputeIntegerHash(key, seed); | |
| 4552 } | |
| 4553 | |
| 4554 uint32_t NumberDictionaryShape::SeededHashForObject(uint32_t key, uint32_t seed, | |
| 4555 Object* other) { | |
|
Erik Corry
2012/01/10 07:29:28
Formatting
| |
| 4556 ASSERT(other->IsNumber()); | |
| 4557 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed); | |
| 4558 } | |
| 4548 | 4559 |
| 4549 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { | 4560 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
| 4550 return Isolate::Current()->heap()->NumberFromUint32(key); | 4561 return Isolate::Current()->heap()->NumberFromUint32(key); |
| 4551 } | 4562 } |
| 4552 | 4563 |
| 4553 | 4564 |
| 4554 bool StringDictionaryShape::IsMatch(String* key, Object* other) { | 4565 bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
| 4555 // We know that all entries in a hash table had their hash keys created. | 4566 // We know that all entries in a hash table had their hash keys created. |
| 4556 // Use that knowledge to have fast failure. | 4567 // Use that knowledge to have fast failure. |
| 4557 if (key->Hash() != String::cast(other)->Hash()) return false; | 4568 if (key->Hash() != String::cast(other)->Hash()) return false; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4769 #undef WRITE_INT_FIELD | 4780 #undef WRITE_INT_FIELD |
| 4770 #undef READ_SHORT_FIELD | 4781 #undef READ_SHORT_FIELD |
| 4771 #undef WRITE_SHORT_FIELD | 4782 #undef WRITE_SHORT_FIELD |
| 4772 #undef READ_BYTE_FIELD | 4783 #undef READ_BYTE_FIELD |
| 4773 #undef WRITE_BYTE_FIELD | 4784 #undef WRITE_BYTE_FIELD |
| 4774 | 4785 |
| 4775 | 4786 |
| 4776 } } // namespace v8::internal | 4787 } } // namespace v8::internal |
| 4777 | 4788 |
| 4778 #endif // V8_OBJECTS_INL_H_ | 4789 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |