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
qv4identifierhash.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
4
5#include <private/qv4identifierhash_p.h>
6#include <private/qv4identifiertable_p.h>
7#include <private/qv4string_p.h>
8#include <private/qv4identifierhashdata_p.h>
9#include <private/qprimefornumbits_p.h>
10
11QT_BEGIN_NAMESPACE
12
13namespace QV4 {
14
20
22{
23 if (!d || d->refCount.loadAcquire() == 1)
24 return;
26 if (d && !d->refCount.deref())
27 delete d;
28 d = newData;
29}
30
31inline
33{
35
36 // fill up to max 50%
37 bool grow = (d->alloc <= d->size*2);
38
39 if (grow) {
40 ++d->numBits;
44 for (int i = 0; i < d->alloc; ++i) {
45 const IdentifierHashEntry &e = d->entries[i];
46 if (!e.identifier.isValid())
47 continue;
49 while (newEntries[idx].identifier.isValid()) {
50 ++idx;
51 idx %= newAlloc;
52 }
53 newEntries[idx] = e;
54 }
55 free(d->entries);
57 d->alloc = newAlloc;
58 }
59
60 uint idx = identifier.id() % d->alloc;
61 while (d->entries[idx].identifier.isValid()) {
63 ++idx;
64 idx %= d->alloc;
65 }
67 ++d->size;
68 return d->entries + idx;
69}
70
71inline
73{
74 if (!d || !identifier.isStringOrSymbol())
75 return nullptr;
77
78 uint idx = identifier.id() % d->alloc;
79 while (1) {
81 return nullptr;
83 return d->entries + idx;
84 ++idx;
85 idx %= d->alloc;
86 }
87}
88
89inline
91{
92 if (!d)
93 return nullptr;
94
96 return lookup(id);
97}
98
99inline
101{
102 if (!d)
103 return nullptr;
105 if (id.isValid())
106 return lookup(id);
107 return lookup(str->toQString());
108}
109
110inline
112{
113 Q_ASSERT(d);
115}
116
117inline
119{
120 Q_ASSERT(d);
122}
123
125{
128 while (e < end) {
129 if (e->identifier.isValid() && e->value == value)
130 return e->identifier.toQString();
131 ++e;
132 }
133 return QString();
134}
135
137{
138 d = other.d;
139 if (d)
140 d->refCount.ref();
141}
142
144{
145 if (d && !d->refCount.deref())
146 delete d;
147}
148
150{
151 if (other.d)
152 other.d->refCount.ref();
153 if (d && !d->refCount.deref())
154 delete d;
155 d = other.d;
156 return *this;
157}
158
160{
161 return d ? d->size : 0;
162}
163
165{
167 e->value = value;
168}
169
175
176int QV4::IdentifierHash::value(const QString &str) const
177{
179 return e ? e->value : -1;
180}
181
183{
185 return e ? e->value : -1;
186}
187
188
189}
190
191QT_END_NAMESPACE
Definition qjsvalue.h:23