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