diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2024-08-27 21:11:29 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2024-10-03 18:54:33 -0700 |
| commit | 518fa1baf7bbc93b80567691d682ae64032fde76 (patch) | |
| tree | 0a9d7088a20e0a633187e792e77edb1049b886f3 /src/corelib/kernel/qmetaobjectbuilder.cpp | |
| parent | 20b6ebea84997ecd70d37640f68232c60cc7231f (diff) | |
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 <fabian.kosmale@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Diffstat (limited to 'src/corelib/kernel/qmetaobjectbuilder.cpp')
| -rw-r--r-- | src/corelib/kernel/qmetaobjectbuilder.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
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. |
