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
qv4string_p.h
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#ifndef QV4STRING_H
4#define QV4STRING_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtCore/qstring.h>
18#include "qv4managed_p.h"
19#include <QtCore/private/qnumeric_p.h>
21#include <private/qv4stringtoarrayindex_p.h>
22
24
25namespace QV4 {
26
27struct ExecutionEngine;
28struct PropertyKey;
29
30namespace Heap {
31
33{
43
44 void init() {
45 Base::init();
47 }
48
50 {
51 Base::init();
53 }
54
55 mutable struct { alignas(QStringPrivate) unsigned char data[sizeof(QStringPrivate)]; } textStorage;
57 mutable uint subtype;
59
61 void destroy();
62
63 QStringPrivate &text() const { return *reinterpret_cast<QStringPrivate *>(&textStorage); }
64
65 inline QString toQString() const {
67 return QString(std::move(dd));
68 }
69 void createHashValue() const;
70 inline unsigned hashValue() const {
74
75 return stringHash;
76 }
77};
78
81
82 const VTable *vtable() const {
83 return internalClass->vtable;
84 }
85
86 void init(const QString &text);
87 void simplifyString() const;
88 int length() const;
90 return subtype >= StringType_Complex ? 0 : (std::size_t(text().size) * sizeof(QChar));
91 }
92 inline QString toQString() const {
95 return StringOrSymbol::toQString();
96 }
97 inline bool isEqualTo(const String *other) const {
98 if (this == other)
99 return true;
100 if (hashValue() != other->hashValue())
101 return false;
104 return true;
106 return true;
107
108 return toQString() == other->toQString();
109 }
110
111 bool startsWithUpper() const;
112
113private:
114 static void append(const String *data, QChar *ch);
115};
117
119 void init(String *l, String *n);
120 void init(String *ref, int from, int len);
121 mutable String *left;
122 mutable String *right;
123 union {
124 mutable int largestSubLength;
125 int from;
126 };
127 int len;
128};
130
131inline
132int String::length() const {
133 // TODO: ensure that our strings never actually grow larger than INT_MAX
134 return subtype < StringType_AddedString ? int(text().size) : static_cast<const ComplexString *>(this)->len;
135}
136
137}
138
139struct Q_QML_EXPORT StringOrSymbol : public Managed {
142 enum {
143 IsStringOrSymbol = true
144 };
145
146private:
147 inline void createPropertyKey() const;
148public:
151
152
153 inline QString toQString() const {
154 return d()->toQString();
155 }
156};
157
158struct Q_QML_EXPORT String : public StringOrSymbol {
162 enum {
163 IsString = true
164 };
165
166 uchar subtype() const { return d()->subtype; }
167 void setSubtype(uchar subtype) const { d()->subtype = subtype; }
168
169 bool equals(String *other) const {
170 return d()->isEqualTo(other->d());
171 }
172 inline bool isEqualTo(const String *other) const {
173 return d()->isEqualTo(other->d());
174 }
175
176 inline bool lessThan(const String *other) {
177 return toQString() < other->toQString();
178 }
179
180 inline QString toQString() const {
181 return d()->toQString();
182 }
183
184 inline unsigned hashValue() const {
185 return d()->hashValue();
186 }
187 uint toUInt(bool *ok) const;
188
189 // slow path
191
193 {
194 const QChar *end = ch + length;
196 }
197
203
204 static uint createHashValue(const char *ch, int length, uint *subtype)
205 {
206 const char *end = ch + length;
208 }
209
210 bool startsWithUpper() const { return d()->startsWithUpper(); }
211
212protected:
213 static bool virtualIsEqualTo(Managed *that, Managed *o);
214 static qint64 virtualGetLength(const Managed *m);
215
216public:
218 template <IndicesBehavior Behavior = Default, typename T>
219 static inline uint calculateHashValue(const T *ch, const T* end, uint *subtype)
220 {
221 // array indices get their number as hash value
222 uint h = UINT_MAX;
223 if constexpr (Behavior != DisallowArrayIndex) {
225 if (h != UINT_MAX) {
226 if (subtype)
228 return h;
229 }
230 }
231
232 while (ch < end) {
233 h = 31 * h + charToUInt(ch);
234 ++ch;
235 }
236
237 if (subtype)
239 return h;
240 }
241};
242
245 QV4::Heap::ComplexString *d_unchecked() const { return static_cast<QV4::Heap::ComplexString *>(m()); }
246 QV4::Heap::ComplexString *d() const {
248 dptr->_checkIsInitialized();
249 return dptr;
250 }
251};
252
253inline
254void StringOrSymbol::createPropertyKey() const {
257 static_cast<const String *>(this)->createPropertyKeyImpl();
258}
259
261 if (!d()->identifier.isValid())
263 return d()->identifier;
264}
265
266template<>
267inline const StringOrSymbol *Value::as() const {
268 return isManaged() && m()->internalClass->vtable->isStringOrSymbol ? static_cast<const String *>(this) : nullptr;
269}
270
271template<>
272inline const String *Value::as() const {
273 return isManaged() && m()->internalClass->vtable->isString ? static_cast<const String *>(this) : nullptr;
274}
275
276template<>
277inline ReturnedValue value_convert<String>(ExecutionEngine *e, const Value &v)
278{
279 return v.toString(e)->asReturnedValue();
280}
281
282}
283
284QT_END_NAMESPACE
285
286#endif
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(StrictArgumentsObject, Object)
DECLARE_HEAP_OBJECT(TypedArray, Object)
DECLARE_HEAP_OBJECT(DataView, Object)
Q_STATIC_ASSERT(std::is_trivial_v< ArrayData >)
Definition qjsvalue.h:23
@ NTypedArrayTypes
@ Float64Array
@ Float32Array
@ UInt16Array
@ UInt8ClampedArray
@ UInt32Array
@ AtomicExchange
@ NAtomicModifyOps
ReturnedValue value_convert< String >(ExecutionEngine *e, const Value &v)
DEFINE_OBJECT_VTABLE(SharedArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBuffer)
DEFINE_OBJECT_VTABLE(SharedArrayBuffer)
#define V4_MANAGED(DataClass, superClass)
#define V4_NEEDS_DESTROY
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define RETURN_UNDEFINED()
static ReturnedValue method_isView(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
QV4::Heap::ComplexString * d_unchecked() const
QV4::Heap::ComplexString * d() const
QV4::Heap::ComplexString Data
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_buffer(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_setFloat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_getChar(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_getFloat(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_setChar(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_get(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_set(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteOffset(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(QV4::ExecutionEngine *engine)
void init(String *l, String *n)
Definition qv4string.cpp:62
void init(String *ref, int from, int len)
Definition qv4string.cpp:84
void init(ExecutionEngine *engine)
void init(QV4::ExecutionEngine *engine)
void init(ExecutionEngine *engine)
Definition qv4symbol.cpp:22
void init(const QString &s)
Definition qv4symbol.cpp:14
void init(ExecutionEngine *engine, TypedArray::Type t)
void init(TypedArray::Type t)
static ReturnedValue method_from(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_entries(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_find(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_filter(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_lastIndexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_buffer(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_length(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_keys(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reverse(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reduce(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_includes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_map(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_set(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_reduceRight(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_findIndex(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_indexOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_join(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_some(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteOffset(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_toStringTag(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_subarray(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_forEach(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_copyWithin(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_values(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_every(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_fill(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc, bool shared)
static ReturnedValue method_keyFor(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
Definition qv4symbol.cpp:62
static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *newTarget)
Definition qv4symbol.cpp:46
static ReturnedValue method_for(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
Definition qv4symbol.cpp:51
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_symbolToPrimitive(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static V4_NEEDS_DESTROY Heap::Symbol * create(ExecutionEngine *e, const QString &s)
QString descriptiveString() const
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static constexpr TypedArrayOperations create(const char *name)
void(*) Write(char *data, Value value)
ReturnedValue(*) AtomicCompareExchange(char *data, Value expected, Value v)
ReturnedValue(*) AtomicStore(char *data, Value value)
ReturnedValue(*) Read(const char *data)
AtomicModify atomicModifyOps[AtomicModifyOps::NAtomicModifyOps]
ReturnedValue(*) AtomicModify(char *data, Value value)
static constexpr TypedArrayOperations createWithAtomics(const char *name)
AtomicCompareExchange atomicCompareExchange
ReturnedValue(*) AtomicLoad(char *data)