V8 Project
v8::internal::TwoCharHashTableKey Class Reference
+ Inheritance diagram for v8::internal::TwoCharHashTableKey:
+ Collaboration diagram for v8::internal::TwoCharHashTableKey:

Public Member Functions

 TwoCharHashTableKey (uint16_t c1, uint16_t c2, uint32_t seed)
 
bool IsMatch (Object *o) OVERRIDE
 
uint32_t Hash () OVERRIDE
 
uint32_t HashForObject (Object *key) OVERRIDE
 
Handle< ObjectAsHandle (Isolate *isolate) OVERRIDE
 
- Public Member Functions inherited from v8::internal::HashTableKey
virtual ~HashTableKey ()
 

Private Attributes

uint16_t c1_
 
uint16_t c2_
 
uint32_t hash_
 

Detailed Description

Definition at line 14604 of file objects.cc.

Constructor & Destructor Documentation

◆ TwoCharHashTableKey()

v8::internal::TwoCharHashTableKey::TwoCharHashTableKey ( uint16_t  c1,
uint16_t  c2,
uint32_t  seed 
)
inline

Definition at line 14606 of file objects.cc.

14607  : c1_(c1), c2_(c2) {
14608  // Char 1.
14609  uint32_t hash = seed;
14610  hash += c1;
14611  hash += hash << 10;
14612  hash ^= hash >> 6;
14613  // Char 2.
14614  hash += c2;
14615  hash += hash << 10;
14616  hash ^= hash >> 6;
14617  // GetHash.
14618  hash += hash << 3;
14619  hash ^= hash >> 11;
14620  hash += hash << 15;
14621  if ((hash & String::kHashBitMask) == 0) hash = StringHasher::kZeroHash;
14622  hash_ = hash;
14623 #ifdef DEBUG
14624  // If this assert fails then we failed to reproduce the two-character
14625  // version of the string hashing algorithm above. One reason could be
14626  // that we were passed two digits as characters, since the hash
14627  // algorithm is different in that case.
14628  uint16_t chars[2] = {c1, c2};
14629  uint32_t check_hash = StringHasher::HashSequentialString(chars, 2, seed);
14631  DCHECK_EQ(static_cast<int32_t>(hash), static_cast<int32_t>(check_hash));
14632 #endif
14633  }
static const int kHashShift
Definition: objects.h:8499
static const uint32_t kHashBitMask
Definition: objects.h:8503
static const int kIsNotArrayIndexMask
Definition: objects.h:8495
static const int kZeroHash
Definition: objects.h:8363
static uint32_t HashSequentialString(const schar *chars, int length, uint32_t seed)
Definition: objects-inl.h:6563
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
unsigned short uint16_t
Definition: unicode.cc:23
int int32_t
Definition: unicode.cc:24

References DCHECK_EQ, v8::internal::StringHasher::HashSequentialString(), v8::internal::Name::kHashBitMask, v8::internal::Name::kHashShift, v8::internal::Name::kIsNotArrayIndexMask, and v8::internal::StringHasher::kZeroHash.

+ Here is the call graph for this function:

Member Function Documentation

◆ AsHandle()

Handle<Object> v8::internal::TwoCharHashTableKey::AsHandle ( Isolate isolate)
inlinevirtual

Implements v8::internal::HashTableKey.

Definition at line 14649 of file objects.cc.

14649  {
14650  // The TwoCharHashTableKey is only used for looking in the string
14651  // table, not for adding to it.
14652  UNREACHABLE();
14653  return MaybeHandle<Object>().ToHandleChecked();
14654  }
#define UNREACHABLE()
Definition: logging.h:30

References UNREACHABLE.

◆ Hash()

uint32_t v8::internal::TwoCharHashTableKey::Hash ( )
inlinevirtual

Implements v8::internal::HashTableKey.

Definition at line 14643 of file objects.cc.

14643 { return hash_; }

◆ HashForObject()

uint32_t v8::internal::TwoCharHashTableKey::HashForObject ( Object key)
inlinevirtual

Implements v8::internal::HashTableKey.

Definition at line 14644 of file objects.cc.

14644  {
14645  if (!key->IsString()) return 0;
14646  return String::cast(key)->Hash();
14647  }

◆ IsMatch()

bool v8::internal::TwoCharHashTableKey::IsMatch ( Object o)
inlinevirtual

Implements v8::internal::HashTableKey.

Definition at line 14635 of file objects.cc.

14635  {
14636  if (!o->IsString()) return false;
14637  String* other = String::cast(o);
14638  if (other->length() != 2) return false;
14639  if (other->Get(0) != c1_) return false;
14640  return other->Get(1) == c2_;
14641  }

References v8::internal::String::length().

+ Here is the call graph for this function:

Member Data Documentation

◆ c1_

uint16_t v8::internal::TwoCharHashTableKey::c1_
private

Definition at line 14657 of file objects.cc.

◆ c2_

uint16_t v8::internal::TwoCharHashTableKey::c2_
private

Definition at line 14658 of file objects.cc.

◆ hash_

uint32_t v8::internal::TwoCharHashTableKey::hash_
private

Definition at line 14659 of file objects.cc.


The documentation for this class was generated from the following file: