V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
lookup-cache-inl.h
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_LOOKUP_CACHE_INL_H_
6 #define V8_LOOKUP_CACHE_INL_H_
7 
8 #include "src/lookup-cache.h"
9 
10 #include "src/objects-inl.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 // static
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 =
20  static_cast<uint32_t>(source.ptr()) >> kPointerSizeLog2;
21  uint32_t name_hash = name->hash_field();
22  return (source_hash ^ name_hash) % kLength;
23 }
24 
25 int DescriptorLookupCache::Lookup(Map source, Name name) {
26  int index = Hash(source, name);
27  Key& key = keys_[index];
28  if ((key.source == source) && (key.name == name)) return results_[index];
29  return kAbsent;
30 }
31 
32 void DescriptorLookupCache::Update(Map source, Name name, int result) {
33  DCHECK_NE(result, kAbsent);
34  int index = Hash(source, name);
35  Key& key = keys_[index];
36  key.source = source;
37  key.name = name;
38  results_[index] = result;
39 }
40 
41 } // namespace internal
42 } // namespace v8
43 
44 #endif // V8_LOOKUP_CACHE_INL_H_
Definition: libplatform.h:13