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{
24
25 // fill up to max 50%
26 bool grow = (d->alloc <= d->size*2);
27
28 if (grow) {
29 ++d->numBits;
33 for (int i = 0; i < d->alloc; ++i) {
34 const IdentifierHashEntry &e = d->entries[i];
35 if (!e.identifier.isValid())
36 continue;
38 while (newEntries[idx].identifier.isValid()) {
39 ++idx;
40 idx %= newAlloc;
41 }
42 newEntries[idx] = e;
43 }
44 free(d->entries);
46 d->alloc = newAlloc;
47 }
48
49 uint idx = identifier.id() % d->alloc;
50 while (d->entries[idx].identifier.isValid()) {
52 ++idx;
53 idx %= d->alloc;
54 }
56 ++d->size;
57 (d->entries + idx)->value = value;
58}
59
61{
62 if (!d || !identifier.isStringOrSymbol())
63 return -1;
65
66 uint idx = identifier.id() % d->alloc;
67 while (1) {
69 return -1;
71 return (d->entries + idx)->value;
72 ++idx;
73 idx %= d->alloc;
74 }
75}
76
78{
79 Q_ASSERT(d);
81}
82
84{
85 Q_ASSERT(d);
87}
88
90{
93 while (e < end) {
94 if (e->identifier.isValid() && e->value == value)
95 return e->identifier;
96 ++e;
97 }
98 return PropertyKey::invalid();
99}
100
101template<>
103{
104 return key.isValid() ? key.toQString() : QString();
105}
106
107template<>
109{
110 return key.isString() ? static_cast<Heap::String *>(key.asStringOrSymbol()) : nullptr;
111}
112
114{
115 d = other.d;
116 if (d)
117 d->refCount.ref();
118}
119
121{
122 if (d && !d->refCount.deref())
123 delete d;
124}
125
127{
128 if (other.d)
129 other.d->refCount.ref();
130 if (d && !d->refCount.deref())
131 delete d;
132 d = other.d;
133 return *this;
134}
135
137{
138 return d ? d->size : 0;
139}
140
141} // namespace QV4
142
143QT_END_NAMESPACE
Definition qjsvalue.h:24