Home | History | Annotate | Download | only in src
      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(Object* 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>(reinterpret_cast<uintptr_t>(source)) >>
     21       kPointerSizeLog2;
     22   uint32_t name_hash = name->hash_field();
     23   return (source_hash ^ name_hash) % kLength;
     24 }
     25 
     26 int DescriptorLookupCache::Lookup(Map* source, Name* name) {
     27   int index = Hash(source, name);
     28   Key& key = keys_[index];
     29   if ((key.source == source) && (key.name == name)) return results_[index];
     30   return kAbsent;
     31 }
     32 
     33 void DescriptorLookupCache::Update(Map* source, Name* name, int result) {
     34   DCHECK_NE(result, kAbsent);
     35   int index = Hash(source, name);
     36   Key& key = keys_[index];
     37   key.source = source;
     38   key.name = name;
     39   results_[index] = result;
     40 }
     41 
     42 }  // namespace internal
     43 }  // namespace v8
     44 
     45 #endif  // V8_LOOKUP_CACHE_INL_H_
     46