| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/lookup.h" | |
| 6 | |
| 7 namespace v8 { | |
| 8 namespace internal { | |
| 9 | |
| 10 // static | |
| 11 int DescriptorLookupCache::Hash(Object* source, Name* name) { | |
| 12 DCHECK(name->IsUniqueName()); | |
| 13 // Uses only lower 32 bits if pointers are larger. | |
| 14 uint32_t source_hash = | |
| 15 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(source)) >> | |
| 16 kPointerSizeLog2; | |
| 17 uint32_t name_hash = name->hash_field(); | |
| 18 return (source_hash ^ name_hash) % kLength; | |
| 19 } | |
| 20 | |
| 21 int DescriptorLookupCache::Lookup(Map* source, Name* name) { | |
| 22 int index = Hash(source, name); | |
| 23 Key& key = keys_[index]; | |
| 24 if ((key.source == source) && (key.name == name)) return results_[index]; | |
| 25 return kAbsent; | |
| 26 } | |
| 27 | |
| 28 void DescriptorLookupCache::Update(Map* source, Name* name, int result) { | |
| 29 DCHECK(result != kAbsent); | |
| 30 int index = Hash(source, name); | |
| 31 Key& key = keys_[index]; | |
| 32 key.source = source; | |
| 33 key.name = name; | |
| 34 results_[index] = result; | |
| 35 } | |
| 36 | |
| 37 } // namespace internal | |
| 38 } // namespace v8 | |
| OLD | NEW |