V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
string-table.h
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 StringTableKey : public HashTableKey {
17  public:
18  explicit inline StringTableKey(uint32_t hash_field);
19 
20  virtual Handle<String> AsHandle(Isolate* isolate) = 0;
21  uint32_t HashField() const {
22  DCHECK_NE(0, hash_field_);
23  return hash_field_;
24  }
25 
26  protected:
27  inline void set_hash_field(uint32_t hash_field);
28 
29  private:
30  uint32_t hash_field_ = 0;
31 };
32 
33 class StringTableShape : public BaseShape<StringTableKey*> {
34  public:
35  static inline bool IsMatch(Key key, Object* value) {
36  return key->IsMatch(value);
37  }
38 
39  static inline uint32_t Hash(Isolate* isolate, Key key) { return key->Hash(); }
40 
41  static inline uint32_t HashForObject(Isolate* isolate, Object* object);
42 
43  static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
44 
45  static inline RootIndex GetMapRootIndex();
46 
47  static const int kPrefixSize = 0;
48  static const int kEntrySize = 1;
49 };
50 
51 class SeqOneByteString;
52 
53 // StringTable.
54 //
55 // No special elements in the prefix and the element size is 1
56 // because only the string itself (the key) needs to be stored.
57 class StringTable : public HashTable<StringTable, StringTableShape> {
58  public:
59  // Find string in the string table. If it is not there yet, it is
60  // added. The return value is the string found.
61  V8_EXPORT_PRIVATE static Handle<String> LookupString(Isolate* isolate,
62  Handle<String> key);
63  static Handle<String> LookupKey(Isolate* isolate, StringTableKey* key);
64  static Handle<String> AddKeyNoResize(Isolate* isolate, StringTableKey* key);
65  static String ForwardStringIfExists(Isolate* isolate, StringTableKey* key,
66  String string);
67 
68  // Shink the StringTable if it's very empty (kMaxEmptyFactor) to avoid the
69  // performance overhead of re-allocating the StringTable over and over again.
70  static Handle<StringTable> CautiousShrink(Isolate* isolate,
71  Handle<StringTable> table);
72 
73  // Looks up a string that is equal to the given string and returns
74  // string handle if it is found, or an empty handle otherwise.
75  V8_WARN_UNUSED_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
76  Isolate* isolate, uint16_t c1, uint16_t c2);
77  // {raw_string} must be a tagged String pointer.
78  // Returns a tagged pointer: either an internalized string, or a Smi
79  // sentinel.
80  static Address LookupStringIfExists_NoAllocate(Isolate* isolate,
81  Address raw_string);
82 
83  static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
84 
85  DECL_CAST2(StringTable)
86 
87  static const int kMaxEmptyFactor = 4;
88  static const int kMinCapacity = 2048;
89  static const int kMinShrinkCapacity = kMinCapacity;
90 
91  private:
92  template <bool seq_one_byte>
93  friend class JsonParser;
94 
96 };
97 
98 class StringSetShape : public BaseShape<String> {
99  public:
100  static inline bool IsMatch(String key, Object* value);
101  static inline uint32_t Hash(Isolate* isolate, String key);
102  static inline uint32_t HashForObject(Isolate* isolate, Object* object);
103 
104  static const int kPrefixSize = 0;
105  static const int kEntrySize = 1;
106 };
107 
108 class StringSet : public HashTable<StringSet, StringSetShape> {
109  public:
110  static Handle<StringSet> New(Isolate* isolate);
111  static Handle<StringSet> Add(Isolate* isolate, Handle<StringSet> blacklist,
112  Handle<String> name);
113  bool Has(Isolate* isolate, Handle<String> name);
114 
115  DECL_CAST2(StringSet)
116  OBJECT_CONSTRUCTORS(StringSet, HashTable<StringSet, StringSetShape>)
117 };
118 
119 } // namespace internal
120 } // namespace v8
121 
122 #include "src/objects/object-macros-undef.h"
123 
124 #endif // V8_OBJECTS_STRING_TABLE_H_
Definition: libplatform.h:13