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
4#include <private/qv4identifierhash_p.h>
5#include <private/qv4identifiertable_p.h>
6#include <private/qv4string_p.h>
7#include <private/qv4identifierhashdata_p.h>
8#include <private/qprimefornumbits_p.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace QV4 {
13
19
21{
22 if (!d || d->refCount.loadAcquire() == 1)
23 return;
25 if (d && !d->refCount.deref())
26 delete d;
27 d = newData;
28}
29
30inline
32{
34
35 // fill up to max 50%
36 bool grow = (d->alloc <= d->size*2);
37
38 if (grow) {
39 ++d->numBits;
43 for (int i = 0; i < d->alloc; ++i) {
44 const IdentifierHashEntry &e = d->entries[i];
45 if (!e.identifier.isValid())
46 continue;
48 while (newEntries[idx].identifier.isValid()) {
49 ++idx;
50 idx %= newAlloc;
51 }
52 newEntries[idx] = e;
53 }
54 free(d->entries);
56 d->alloc = newAlloc;
57 }
58
59 uint idx = identifier.id() % d->alloc;
60 while (d->entries[idx].identifier.isValid()) {
62 ++idx;
63 idx %= d->alloc;
64 }
66 ++d->size;
67 return d->entries + idx;
68}
69
70inline
72{
73 if (!d || !identifier.isStringOrSymbol())
74 return nullptr;
76
77 uint idx = identifier.id() % d->alloc;
78 while (1) {
80 return nullptr;
82 return d->entries + idx;
83 ++idx;
84 idx %= d->alloc;
85 }
86}
87
88inline
90{
91 if (!d)
92 return nullptr;
93
95 return lookup(id);
96}
97
98inline
100{
101 if (!d)
102 return nullptr;
104 if (id.isValid())
105 return lookup(id);
106 return lookup(str->toQString());
107}
108
109inline
111{
112 Q_ASSERT(d);
114}
115
116inline
118{
119 Q_ASSERT(d);
121}
122
124{
127 while (e < end) {
128 if (e->identifier.isValid() && e->value == value)
129 return e->identifier.toQString();
130 ++e;
131 }
132 return QString();
133}
134
136{
137 d = other.d;
138 if (d)
139 d->refCount.ref();
140}
141
143{
144 if (d && !d->refCount.deref())
145 delete d;
146}
147
149{
150 if (other.d)
151 other.d->refCount.ref();
152 if (d && !d->refCount.deref())
153 delete d;
154 d = other.d;
155 return *this;
156}
157
159{
160 return d ? d->size : 0;
161}
162
164{
166 e->value = value;
167}
168
174
175int QV4::IdentifierHash::value(const QString &str) const
176{
178 return e ? e->value : -1;
179}
180
182{
184 return e ? e->value : -1;
185}
186
187
188}
189
190QT_END_NAMESPACE
Definition qjsvalue.h:23