Line data Source code
1 : // Copyright 2017 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_H_
6 : #define V8_OBJECTS_STRING_TABLE_H_
7 :
8 : #include "src/objects/hash-table.h"
9 :
10 : // Has to be the last include (doesn't have include guards):
11 : #include "src/objects/object-macros.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 :
16 : class StringTableShape : public BaseShape<HashTableKey*> {
17 : public:
18 : static inline bool IsMatch(HashTableKey* key, Object* value) {
19 165942399 : return key->IsMatch(value);
20 : }
21 :
22 96384327 : static inline uint32_t Hash(HashTableKey* key) { return key->Hash(); }
23 :
24 : static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
25 7401472 : return key->HashForObject(object);
26 : }
27 :
28 : static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
29 :
30 : static const int kPrefixSize = 0;
31 : static const int kEntrySize = 1;
32 : };
33 :
34 : class SeqOneByteString;
35 :
36 : // StringTable.
37 : //
38 : // No special elements in the prefix and the element size is 1
39 : // because only the string itself (the key) needs to be stored.
40 : class StringTable
41 : : public HashTable<StringTable, StringTableShape, HashTableKey*> {
42 : public:
43 : // Find string in the string table. If it is not there yet, it is
44 : // added. The return value is the string found.
45 : V8_EXPORT_PRIVATE static Handle<String> LookupString(Isolate* isolate,
46 : Handle<String> key);
47 : static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
48 : static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key);
49 :
50 : // Tries to internalize given string and returns string handle on success
51 : // or an empty handle otherwise.
52 : MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
53 : Isolate* isolate, Handle<String> string);
54 :
55 : // Looks up a string that is equal to the given string and returns
56 : // string handle if it is found, or an empty handle otherwise.
57 : MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
58 : Isolate* isolate, Handle<String> str);
59 : MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
60 : Isolate* isolate, uint16_t c1, uint16_t c2);
61 : static Object* LookupStringIfExists_NoAllocate(String* string);
62 :
63 : static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
64 :
65 : DECLARE_CAST(StringTable)
66 :
67 : private:
68 : template <bool seq_one_byte>
69 : friend class JsonParser;
70 :
71 : DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable);
72 : };
73 :
74 : class StringSetShape : public BaseShape<String*> {
75 : public:
76 : static inline bool IsMatch(String* key, Object* value);
77 : static inline uint32_t Hash(String* key);
78 : static inline uint32_t HashForObject(String* key, Object* object);
79 :
80 : static const int kPrefixSize = 0;
81 : static const int kEntrySize = 1;
82 : };
83 :
84 : class StringSet : public HashTable<StringSet, StringSetShape, String*> {
85 : public:
86 : static Handle<StringSet> New(Isolate* isolate);
87 : static Handle<StringSet> Add(Handle<StringSet> blacklist,
88 : Handle<String> name);
89 : bool Has(Handle<String> name);
90 :
91 : DECLARE_CAST(StringSet)
92 : };
93 :
94 : } // namespace internal
95 : } // namespace v8
96 :
97 : #include "src/objects/object-macros-undef.h"
98 :
99 : #endif // V8_OBJECTS_STRING_TABLE_H_
|