From 518fa1baf7bbc93b80567691d682ae64032fde76 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 27 Aug 2024 21:11:29 -0700 Subject: QMetaMethod: make some QByteArray-returning methods slightly faster QByteArray::fromRawData() allocates no memory. Since we know that the data range is valid, there's no precondition violation either. But we can only use it for static-lifetime meta objects: those constructed by QMetaObjectBuilder or QtDBus may get deallocated, causing the strings obtained from them to crash on use if they do outlive (unlikely, but not impossible). To differentiate, this commit introduces a new flag to the QMetaObject header and makes use of it in those two places. Come Qt 7, we should change these functions to return QByteArrayView, making the retention of the data in a QByteArray the responsibility of the user. Making the change right now with #if or QTx_ONLY() is ugly, so this commit just leaves a comment. Change-Id: I5aaddbc7ce3fc7a70e15fffd29e276c79d5ef6e4 Reviewed-by: Fabian Kosmale Reviewed-by: Ahmad Samir --- src/corelib/kernel/qmetaobjectbuilder.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/kernel/qmetaobjectbuilder.cpp') diff --git a/src/corelib/kernel/qmetaobjectbuilder.cpp b/src/corelib/kernel/qmetaobjectbuilder.cpp index 179503da51f..e511f14686c 100644 --- a/src/corelib/kernel/qmetaobjectbuilder.cpp +++ b/src/corelib/kernel/qmetaobjectbuilder.cpp @@ -1169,7 +1169,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf, if constexpr (mode == Construct) { static_assert(QMetaObjectPrivate::OutputRevision == 13, "QMetaObjectBuilder should generate the same version as moc"); pmeta->revision = QMetaObjectPrivate::OutputRevision; - pmeta->flags = d->flags.toInt(); + pmeta->flags = d->flags.toInt() | AllocatedMetaObject; pmeta->className = 0; // Class name is always the first string. //pmeta->signalCount is handled in the "output method loop" as an optimization. -- cgit v1.2.3