summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype_p.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-07-05 13:52:38 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-07-27 12:35:50 -0700
commit2e6398bd4626c054f18ca9762523dfcb49e31ab8 (patch)
tree1df9696b2cbb51947ca0a5e77b443b48562a53d8 /src/corelib/kernel/qmetatype_p.h
parentcfdaf9226d5dd15a50cffa38ac39a1e29cb5e2fd (diff)
QMetaType: don't record trivial construction function pointers
We can implement the trivial {default,copy,move} construction outselves inside qmetatype.cpp and qvariant.cpp, simplifying the QMetaType interface object, removing up to three relocations per QMTI. This adds the testing for QMetaType::isXxxConstructible and isDestructible that couldn't be added before. Change-Id: Ic44396b31ba04712aab3fffd16ff0a28f541d507 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qmetatype_p.h')
-rw-r--r--src/corelib/kernel/qmetatype_p.h39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h
index 89f1854bf6..08c1aeaa1d 100644
--- a/src/corelib/kernel/qmetatype_p.h
+++ b/src/corelib/kernel/qmetatype_p.h
@@ -141,21 +141,52 @@ inline bool isDefaultConstructible(const QtPrivate::QMetaTypeInterface *iface) n
inline bool isCopyConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
{
- // ### broken
- return checkMetaTypeFlagOrPointer(iface, iface->copyCtr, QMetaType::NeedsConstruction);
+ return checkMetaTypeFlagOrPointer(iface, iface->copyCtr, QMetaType::NeedsCopyConstruction);
}
inline bool isMoveConstructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
{
- return iface->moveCtr;
+ return checkMetaTypeFlagOrPointer(iface, iface->moveCtr, QMetaType::NeedsMoveConstruction);
}
inline bool isDestructible(const QtPrivate::QMetaTypeInterface *iface) noexcept
{
- // ### broken
return checkMetaTypeFlagOrPointer(iface, iface->dtor, QMetaType::NeedsDestruction);
}
+inline void defaultConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
+{
+ Q_ASSERT(isDefaultConstructible(iface));
+ if (iface->defaultCtr)
+ iface->defaultCtr(iface, where);
+ else
+ memset(where, 0, iface->size);
+}
+
+inline void copyConstruct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
+{
+ Q_ASSERT(isCopyConstructible(iface));
+ if (iface->copyCtr)
+ iface->copyCtr(iface, where, copy);
+ else
+ memcpy(where, copy, iface->size);
+}
+
+inline void construct(const QtPrivate::QMetaTypeInterface *iface, void *where, const void *copy)
+{
+ if (copy)
+ copyConstruct(iface, where, copy);
+ else
+ defaultConstruct(iface, where);
+}
+
+inline void destruct(const QtPrivate::QMetaTypeInterface *iface, void *where)
+{
+ Q_ASSERT(isDestructible(iface));
+ if (iface->dtor)
+ iface->dtor(iface, where);
+}
+
const char *typedefNameForType(const QtPrivate::QMetaTypeInterface *type_d);
template<typename T>