Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qv4identifiertable.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
5#include "qv4symbol_p.h"
6#include <private/qv4identifierhashdata_p.h>
7#include <private/qprimefornumbits_p.h>
8
10
11namespace QV4 {
12
24
26{
29 for (const auto &h : std::as_const(idHashes))
30 h->identifierTable = nullptr;
31}
32
34{
36
38 return;
39
41
42 bool grow = (alloc <= size*2);
43
44 if (grow) {
45 ++numBits;
49 for (uint i = 0; i < alloc; ++i) {
51 if (!e)
52 continue;
54 while (newEntries[idx]) {
55 ++idx;
56 idx %= newAlloc;
57 }
58 newEntries[idx] = e;
59 }
62
65 for (uint i = 0; i < alloc; ++i) {
67 if (!e)
68 continue;
70 while (newEntries[idx]) {
71 ++idx;
72 idx %= newAlloc;
73 }
74 newEntries[idx] = e;
75 }
78
80 }
81
82 uint idx = hash % alloc;
83 while (entriesByHash[idx]) {
84 ++idx;
85 idx %= alloc;
86 }
88
89 idx = str->identifier.id() % alloc;
90 while (entriesById[idx]) {
91 ++idx;
92 idx %= alloc;
93 }
95
96 ++size;
97}
98
99
100
114
116{
117 uint idx = hash % alloc;
118 while (Heap::StringOrSymbol *e = entriesByHash[idx]) {
119 if (e->stringHash == hash && e->toQString() == s)
120 return static_cast<Heap::String *>(e);
121 ++idx;
122 idx %= alloc;
123 }
124
128 addEntry(str);
129 return str;
130}
131
133{
134 Q_ASSERT(s.at(0) == QLatin1Char('@'));
135
138 uint idx = hash % alloc;
139 while (Heap::StringOrSymbol *e = entriesByHash[idx]) {
140 if (e->stringHash == hash && e->toQString() == s)
141 return static_cast<Heap::Symbol *>(e);
142 ++idx;
143 idx %= alloc;
144 }
145
149 addEntry(str);
150 return str;
151
152}
153
154
156{
157 if (str->identifier.isValid())
158 return str->identifier;
159 uint hash = str->hashValue();
162 return str->identifier;
163 }
164
165 uint idx = hash % alloc;
166 while (Heap::StringOrSymbol *e = entriesByHash[idx]) {
167 if (e->stringHash == hash && e->toQString() == str->toQString()) {
171 });
172 return e->identifier;
173 }
174 ++idx;
175 idx %= alloc;
176 }
177
178 addEntry(const_cast<QV4::Heap::String *>(str));
179 return str->identifier;
180}
181
183{
184 if (i.isArrayIndex())
186 if (!i.isValid())
187 return nullptr;
188
189 uint idx = i.id() % alloc;
190 while (1) {
192 if (!e || e->identifier == i)
193 return e;
194 ++idx;
195 idx %= alloc;
196 }
197}
198
200{
203 return static_cast<Heap::String *>(s);
204}
205
207{
210 return static_cast<Heap::Symbol *>(s);
211}
212
214{
215 for (const auto &h : idHashes)
217}
218
220{
221 int freed = 0;
222
224 memset(newTable, 0, alloc*sizeof(Heap::StringOrSymbol *));
226 for (uint i = 0; i < alloc; ++i) {
228 if (!e)
229 continue;
230 if (!e->isMarked()) {
231 ++freed;
232 continue;
233 }
234 uint idx = e->hashValue() % alloc;
235 while (newTable[idx]) {
236 ++idx;
237 if (idx == alloc)
238 idx = 0;
239 }
240 newTable[idx] = e;
241
242 idx = e->identifier.id() % alloc;
243 while (entriesById[idx]) {
244 ++idx;
245 if (idx == alloc)
246 idx = 0;
247 }
248 entriesById[idx] = e;
249 }
252
253 size -= freed;
254}
255
269
270}
271
272QT_END_NAMESPACE
Definition qjsvalue.h:23