From e58b44d557b859b7b55869f1e137aa1bc8968307 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 11 Nov 2019 15:00:51 +0100 Subject: 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 --- src/corelib/kernel/qmetaobjectbuilder.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/corelib/kernel/qmetaobjectbuilder.cpp') 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(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(buf + size); if (buf) { if (relocatable) { - meta->d.stringdata = reinterpret_cast((quintptr)size); + meta->d.stringdata = reinterpret_cast((quintptr)size); meta->d.data = reinterpret_cast((quintptr)pmetaSize); } else { - meta->d.stringdata = reinterpret_cast(str); + meta->d.stringdata = reinterpret_cast(str); meta->d.data = reinterpret_cast(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(buf + stringdataOffset); + output->d.stringdata = reinterpret_cast(buf + stringdataOffset); output->d.data = reinterpret_cast(buf + dataOffset); output->d.extradata = 0; output->d.relatedMetaObjects = 0; -- cgit v1.2.3