• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
Hash(Object * source,Name * name)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       static_cast<uint32_t>(reinterpret_cast<uintptr_t>(source)) >>
18       kPointerSizeLog2;
19   uint32_t name_hash = name->hash_field();
20   return (source_hash ^ name_hash) % kLength;
21 }
22 
Lookup(Map * source,Name * name)23 int DescriptorLookupCache::Lookup(Map* source, Name* name) {
24   int index = Hash(source, name);
25   Key& key = keys_[index];
26   if ((key.source == source) && (key.name == name)) return results_[index];
27   return kAbsent;
28 }
29 
Update(Map * source,Name * name,int result)30 void DescriptorLookupCache::Update(Map* source, Name* name, int result) {
31   DCHECK(result != kAbsent);
32   int index = Hash(source, name);
33   Key& key = keys_[index];
34   key.source = source;
35   key.name = name;
36   results_[index] = result;
37 }
38 
39 }  // namespace internal
40 }  // namespace v8
41