diff options
author | Lars Knoll <lars.knoll@qt.io> | 2019-11-11 15:00:51 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2019-12-08 18:19:58 +0100 |
commit | e58b44d557b859b7b55869f1e137aa1bc8968307 (patch) | |
tree | 5891735d0be64f341e760514b5b576b0d2fd92be /src/corelib | |
parent | 746ab4bbd6ebf2147ce93390738c8a71d6a4a335 (diff) |
Change representation of string data in the meta object
Don't store our string data as QByteArrayLiterals anymore, but revert
back to simply storing them as an array of char* and offsets into that
array.
This is required to be able to inline size and begin into QByteArray
itself. Once that change is done, we can then avoid creating copies of
the string data again.
Change-Id: I362a54581caefdb1b3da4a7ab922d37e2e63dc02
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 33 | ||||
-rw-r--r-- | src/corelib/kernel/qmetaobjectbuilder.cpp | 22 | ||||
-rw-r--r-- | src/corelib/kernel/qobjectdefs.h | 2 |
3 files changed, 30 insertions, 27 deletions
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index f093111a8c..87cced41f8 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -154,19 +154,29 @@ QT_BEGIN_NAMESPACE static inline const QMetaObjectPrivate *priv(const uint* data) { return reinterpret_cast<const QMetaObjectPrivate*>(data); } +static inline const char *rawStringData(const QMetaObject *mo, int index) +{ + Q_ASSERT(priv(mo->d.data)->revision >= 7); + uint offset = mo->d.stringdata[2*index]; + return reinterpret_cast<const char *>(mo->d.stringdata) + offset; +} + static inline const QByteArray stringData(const QMetaObject *mo, int index) { Q_ASSERT(priv(mo->d.data)->revision >= 7); - const QByteArrayDataPtr data = { const_cast<QByteArrayData*>(&mo->d.stringdata[index]) }; - Q_ASSERT(data.ptr->isStatic()); - Q_ASSERT(data.ptr->allocatedCapacity() == 0); - Q_ASSERT(data.ptr->size >= 0); - return data; + uint offset = mo->d.stringdata[2*index]; + uint length = mo->d.stringdata[2*index + 1]; + const char *string = reinterpret_cast<const char *>(mo->d.stringdata) + offset; + return QByteArray::fromRawData(string, length); } -static inline const char *rawStringData(const QMetaObject *mo, int index) +static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo) { - return stringData(mo, index).data(); + if (typeInfo & IsUnresolvedType) { + return rawStringData(mo, typeInfo & TypeNameIndexMask); + } else { + return QMetaType::typeName(typeInfo); + } } static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo) @@ -180,16 +190,11 @@ static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeIn } } -static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo) -{ - return typeNameFromTypeInfo(mo, typeInfo).constData(); -} - static inline int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo) { if (!(typeInfo & IsUnresolvedType)) return typeInfo; - return QMetaType::type(stringData(mo, typeInfo & TypeNameIndexMask)); + return QMetaType::type(rawStringData(mo, typeInfo & TypeNameIndexMask)); } class QMetaMethodPrivate : public QMetaMethod @@ -576,7 +581,7 @@ static bool methodMatch(const QMetaObject *m, int handle, if (int(m->d.data[handle + 1]) != argc) return false; - if (stringData(m, m->d.data[handle]) != name) + if (rawStringData(m, m->d.data[handle]) != name) return false; int paramsIndex = m->d.data[handle + 2] + 1; diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index aab9e05182..2487681f78 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1103,13 +1103,13 @@ int QMetaStringTable::enter(const QByteArray &value) int QMetaStringTable::preferredAlignment() { - return alignof(QByteArrayData); + return alignof(uint); } // Returns the size (in bytes) required for serializing this string table. int QMetaStringTable::blobSize() const { - int size = m_entries.size() * sizeof(QByteArrayData); + int size = m_entries.size() * 2*sizeof(uint); Entries::const_iterator it; for (it = m_entries.constBegin(); it != m_entries.constEnd(); ++it) size += it.key().size() + 1; @@ -1120,14 +1120,12 @@ static void writeString(char *out, int i, const QByteArray &str, const int offsetOfStringdataMember, int &stringdataOffset) { int size = str.size(); - qptrdiff offset = offsetOfStringdataMember + stringdataOffset - - i * sizeof(QByteArrayData); - const QByteArrayData data = - Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset); + int offset = offsetOfStringdataMember + stringdataOffset; + uint offsetLen[2] = { uint(offset), uint(size) }; - memcpy(out + i * sizeof(QByteArrayData), &data, sizeof(QByteArrayData)); + memcpy(out + 2 * i * sizeof(uint), &offsetLen, 2*sizeof(uint)); - memcpy(out + offsetOfStringdataMember + stringdataOffset, str.constData(), size); + memcpy(out + offset, str.constData(), size); out[offsetOfStringdataMember + stringdataOffset + size] = '\0'; stringdataOffset += size + 1; @@ -1141,7 +1139,7 @@ void QMetaStringTable::writeBlob(char *out) const { Q_ASSERT(!(reinterpret_cast<quintptr>(out) & (preferredAlignment()-1))); - int offsetOfStringdataMember = m_entries.size() * sizeof(QByteArrayData); + int offsetOfStringdataMember = m_entries.size() * 2*sizeof(uint); int stringdataOffset = 0; // qt_metacast expects the first string in the string table to be the class name. @@ -1282,10 +1280,10 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, char *str = reinterpret_cast<char *>(buf + size); if (buf) { if (relocatable) { - meta->d.stringdata = reinterpret_cast<const QByteArrayData *>((quintptr)size); + meta->d.stringdata = reinterpret_cast<const uint *>((quintptr)size); meta->d.data = reinterpret_cast<uint *>((quintptr)pmetaSize); } else { - meta->d.stringdata = reinterpret_cast<const QByteArrayData *>(str); + meta->d.stringdata = reinterpret_cast<const uint *>(str); meta->d.data = reinterpret_cast<uint *>(data); } } @@ -1553,7 +1551,7 @@ void QMetaObjectBuilder::fromRelocatableData(QMetaObject *output, quintptr dataOffset = (quintptr)dataMo->d.data; output->d.superdata = superclass; - output->d.stringdata = reinterpret_cast<const QByteArrayData *>(buf + stringdataOffset); + output->d.stringdata = reinterpret_cast<const uint *>(buf + stringdataOffset); output->d.data = reinterpret_cast<const uint *>(buf + dataOffset); output->d.extradata = 0; output->d.relatedMetaObjects = 0; diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 90e3aa02d8..c4b9979293 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -424,7 +424,7 @@ struct Q_CORE_EXPORT QMetaObject struct { // private data SuperData superdata; - const QByteArrayData *stringdata; + const uint *stringdata; const uint *data; typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **); StaticMetacallFunction static_metacall; |