| 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 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2070 template<typename Shape, typename Key> | 2070 template<typename Shape, typename Key> |
| 2071 int HashTable<Shape, Key>::FindEntry(Key key) { | 2071 int HashTable<Shape, Key>::FindEntry(Key key) { |
| 2072 return FindEntry(GetIsolate(), key); | 2072 return FindEntry(GetIsolate(), key); |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 | 2075 |
| 2076 // Find entry for key otherwise return kNotFound. | 2076 // Find entry for key otherwise return kNotFound. |
| 2077 template<typename Shape, typename Key> | 2077 template<typename Shape, typename Key> |
| 2078 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { | 2078 int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { |
| 2079 uint32_t capacity = Capacity(); | 2079 uint32_t capacity = Capacity(); |
| 2080 uint32_t entry = FirstProbe(Shape::Hash(key), capacity); | 2080 uint32_t entry = FirstProbe(HashTable<Shape, Key>::Hash(key), capacity); |
| 2081 uint32_t count = 1; | 2081 uint32_t count = 1; |
| 2082 // EnsureCapacity will guarantee the hash table is never full. | 2082 // EnsureCapacity will guarantee the hash table is never full. |
| 2083 while (true) { | 2083 while (true) { |
| 2084 Object* element = KeyAt(entry); | 2084 Object* element = KeyAt(entry); |
| 2085 // Empty entry. | 2085 // Empty entry. |
| 2086 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; | 2086 if (element == isolate->heap()->raw_unchecked_undefined_value()) break; |
| 2087 if (element != isolate->heap()->raw_unchecked_null_value() && | 2087 if (element != isolate->heap()->raw_unchecked_null_value() && |
| 2088 Shape::IsMatch(key, element)) return entry; | 2088 Shape::IsMatch(key, element)) return entry; |
| 2089 entry = NextProbe(entry, count++, capacity); | 2089 entry = NextProbe(entry, count++, capacity); |
| 2090 } | 2090 } |
| (...skipping 2145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4236 } | 4236 } |
| 4237 | 4237 |
| 4238 | 4238 |
| 4239 StringHasher::StringHasher(int length, uint32_t seed) | 4239 StringHasher::StringHasher(int length, uint32_t seed) |
| 4240 : length_(length), | 4240 : length_(length), |
| 4241 raw_running_hash_(seed), | 4241 raw_running_hash_(seed), |
| 4242 array_index_(0), | 4242 array_index_(0), |
| 4243 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), | 4243 is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
| 4244 is_first_char_(true), | 4244 is_first_char_(true), |
| 4245 is_valid_(true) { | 4245 is_valid_(true) { |
| 4246 ASSERT(FLAG_randomize_string_hashes || raw_running_hash_ == 0); | 4246 ASSERT(FLAG_randomize_hashes || raw_running_hash_ == 0); |
| 4247 } | 4247 } |
| 4248 | 4248 |
| 4249 | 4249 |
| 4250 bool StringHasher::has_trivial_hash() { | 4250 bool StringHasher::has_trivial_hash() { |
| 4251 return length_ > String::kMaxHashCalcLength; | 4251 return length_ > String::kMaxHashCalcLength; |
| 4252 } | 4252 } |
| 4253 | 4253 |
| 4254 | 4254 |
| 4255 void StringHasher::AddCharacter(uc32 c) { | 4255 void StringHasher::AddCharacter(uc32 c) { |
| 4256 // Use the Jenkins one-at-a-time hash function to update the hash | 4256 // Use the Jenkins one-at-a-time hash function to update the hash |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4470 } | 4470 } |
| 4471 | 4471 |
| 4472 | 4472 |
| 4473 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { | 4473 bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
| 4474 ASSERT(other->IsNumber()); | 4474 ASSERT(other->IsNumber()); |
| 4475 return key == static_cast<uint32_t>(other->Number()); | 4475 return key == static_cast<uint32_t>(other->Number()); |
| 4476 } | 4476 } |
| 4477 | 4477 |
| 4478 | 4478 |
| 4479 uint32_t NumberDictionaryShape::Hash(uint32_t key) { | 4479 uint32_t NumberDictionaryShape::Hash(uint32_t key) { |
| 4480 return ComputeIntegerHash(key); | 4480 // This function is unreachable, since shape has UsesSeed=true flag. |
| 4481 UNREACHABLE(); |
| 4482 return 0; |
| 4481 } | 4483 } |
| 4482 | 4484 |
| 4483 | 4485 |
| 4484 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { | 4486 uint32_t NumberDictionaryShape::HashForObject(uint32_t key, Object* other) { |
| 4485 ASSERT(other->IsNumber()); | 4487 // This function is unreachable, since shape has UsesSeed=true flag. |
| 4486 return ComputeIntegerHash(static_cast<uint32_t>(other->Number())); | 4488 UNREACHABLE(); |
| 4489 return 0; |
| 4487 } | 4490 } |
| 4488 | 4491 |
| 4492 uint32_t NumberDictionaryShape::SeededHash(uint32_t key, uint32_t seed) { |
| 4493 return ComputeIntegerHash(key, seed); |
| 4494 } |
| 4495 |
| 4496 uint32_t NumberDictionaryShape::SeededHashForObject(uint32_t key, |
| 4497 uint32_t seed, |
| 4498 Object* other) { |
| 4499 ASSERT(other->IsNumber()); |
| 4500 return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed); |
| 4501 } |
| 4489 | 4502 |
| 4490 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { | 4503 MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
| 4491 return Isolate::Current()->heap()->NumberFromUint32(key); | 4504 return Isolate::Current()->heap()->NumberFromUint32(key); |
| 4492 } | 4505 } |
| 4493 | 4506 |
| 4494 | 4507 |
| 4495 bool StringDictionaryShape::IsMatch(String* key, Object* other) { | 4508 bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
| 4496 // We know that all entries in a hash table had their hash keys created. | 4509 // We know that all entries in a hash table had their hash keys created. |
| 4497 // Use that knowledge to have fast failure. | 4510 // Use that knowledge to have fast failure. |
| 4498 if (key->Hash() != String::cast(other)->Hash()) return false; | 4511 if (key->Hash() != String::cast(other)->Hash()) return false; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4689 #undef WRITE_INT_FIELD | 4702 #undef WRITE_INT_FIELD |
| 4690 #undef READ_SHORT_FIELD | 4703 #undef READ_SHORT_FIELD |
| 4691 #undef WRITE_SHORT_FIELD | 4704 #undef WRITE_SHORT_FIELD |
| 4692 #undef READ_BYTE_FIELD | 4705 #undef READ_BYTE_FIELD |
| 4693 #undef WRITE_BYTE_FIELD | 4706 #undef WRITE_BYTE_FIELD |
| 4694 | 4707 |
| 4695 | 4708 |
| 4696 } } // namespace v8::internal | 4709 } } // namespace v8::internal |
| 4697 | 4710 |
| 4698 #endif // V8_OBJECTS_INL_H_ | 4711 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |