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 #ifndef V8_OBJECTS_LOOKUP_CACHE_INL_H_
6 #define V8_OBJECTS_LOOKUP_CACHE_INL_H_
7 
8 #include "src/objects/lookup-cache.h"
9 
10 #include "src/objects/objects-inl.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 // static
Hash(Map source,Name name)16 int DescriptorLookupCache::Hash(Map source, Name name) {
17   DCHECK(name.IsUniqueName());
18   // Uses only lower 32 bits if pointers are larger.
19   uint32_t source_hash = static_cast<uint32_t>(source.ptr()) >> kTaggedSizeLog2;
20   uint32_t name_hash = name.hash_field();
21   return (source_hash ^ name_hash) % kLength;
22 }
23 
Lookup(Map source,Name name)24 int DescriptorLookupCache::Lookup(Map source, Name name) {
25   int index = Hash(source, name);
26   Key& key = keys_[index];
27   if ((key.source == source) && (key.name == name)) return results_[index];
28   return kAbsent;
29 }
30 
Update(Map source,Name name,int result)31 void DescriptorLookupCache::Update(Map source, Name name, int result) {
32   DCHECK_NE(result, kAbsent);
33   int index = Hash(source, name);
34   Key& key = keys_[index];
35   key.source = source;
36   key.name = name;
37   results_[index] = result;
38 }
39 
40 }  // namespace internal
41 }  // namespace v8
42 
43 #endif  // V8_OBJECTS_LOOKUP_CACHE_INL_H_
44