1 // Copyright 2018 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_OBJECTS_STRING_TABLE_INL_H_
6 #define V8_OBJECTS_STRING_TABLE_INL_H_
7
8 #include "src/objects/string-table.h"
9
10 #include "src/objects/string-inl.h"
11
12 // Has to be the last include (doesn't have include guards):
13 #include "src/objects/object-macros.h"
14
15 namespace v8 {
16 namespace internal {
17
18 CAST_ACCESSOR(StringSet)
CAST_ACCESSOR(StringTable)19 CAST_ACCESSOR(StringTable)
20
21 StringTable::StringTable(Address ptr)
22 : HashTable<StringTable, StringTableShape>(ptr) {
23 SLOW_DCHECK(IsStringTable());
24 }
25
StringSet(Address ptr)26 StringSet::StringSet(Address ptr) : HashTable<StringSet, StringSetShape>(ptr) {
27 SLOW_DCHECK(IsStringSet());
28 }
29
IsMatch(String key,Object value)30 bool StringSetShape::IsMatch(String key, Object value) {
31 DCHECK(value.IsString());
32 return key.Equals(String::cast(value));
33 }
34
Hash(ReadOnlyRoots roots,String key)35 uint32_t StringSetShape::Hash(ReadOnlyRoots roots, String key) {
36 return key.Hash();
37 }
38
HashForObject(ReadOnlyRoots roots,Object object)39 uint32_t StringSetShape::HashForObject(ReadOnlyRoots roots, Object object) {
40 return String::cast(object).Hash();
41 }
42
IsMatch(Key key,Object value)43 bool StringTableShape::IsMatch(Key key, Object value) {
44 String string = String::cast(value);
45 if (string.hash_field() != key->hash_field()) return false;
46 if (string.length() != key->length()) return false;
47 return key->IsMatch(string);
48 }
49
StringTableKey(uint32_t hash_field,int length)50 StringTableKey::StringTableKey(uint32_t hash_field, int length)
51 : hash_field_(hash_field), length_(length) {}
52
set_hash_field(uint32_t hash_field)53 void StringTableKey::set_hash_field(uint32_t hash_field) {
54 hash_field_ = hash_field;
55 }
56
hash()57 uint32_t StringTableKey::hash() const {
58 return hash_field_ >> Name::kHashShift;
59 }
60
61 // static
Hash(ReadOnlyRoots roots,Key key)62 uint32_t StringTableShape::Hash(ReadOnlyRoots roots, Key key) {
63 return key->hash();
64 }
65
AsHandle(Isolate * isolate,StringTableKey * key)66 Handle<Object> StringTableShape::AsHandle(Isolate* isolate,
67 StringTableKey* key) {
68 return key->AsHandle(isolate);
69 }
70
HashForObject(ReadOnlyRoots roots,Object object)71 uint32_t StringTableShape::HashForObject(ReadOnlyRoots roots, Object object) {
72 return String::cast(object).Hash();
73 }
74
GetMap(ReadOnlyRoots roots)75 Handle<Map> StringTableShape::GetMap(ReadOnlyRoots roots) {
76 return roots.string_table_map_handle();
77 }
78
79 } // namespace internal
80 } // namespace v8
81
82 #include "src/objects/object-macros-undef.h"
83
84 #endif // V8_OBJECTS_STRING_TABLE_INL_H_
85