From 2e6398bd4626c054f18ca9762523dfcb49e31ab8 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 5 Jul 2022 13:52:38 -0700 Subject: 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 --- src/corelib/kernel/qmetatype.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/corelib/kernel/qmetatype.h') diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 28d246d2cf..7a66767258 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -381,6 +381,9 @@ public: IsPointer = 0x800, IsQmlList =0x1000, // used in the QML engine to recognize QQmlListProperty and list IsConst = 0x2000, + // since 6.5: + NeedsCopyConstruction = 0x4000, + NeedsMoveConstruction = 0x8000, }; Q_DECLARE_FLAGS(TypeFlags, TypeFlag) @@ -1187,8 +1190,10 @@ namespace QtPrivate { struct QMetaTypeTypeFlags { enum { Flags = (QTypeInfo::isRelocatable ? QMetaType::RelocatableType : 0) - | (QTypeInfo::isComplex ? QMetaType::NeedsConstruction : 0) - | (QTypeInfo::isComplex ? QMetaType::NeedsDestruction : 0) + | (!std::is_trivially_default_constructible_v ? QMetaType::NeedsConstruction : 0) + | (!std::is_trivially_destructible_v ? QMetaType::NeedsDestruction : 0) + | (!std::is_trivially_copy_constructible_v ? QMetaType::NeedsCopyConstruction : 0) + | (!std::is_trivially_move_constructible_v ? QMetaType::NeedsMoveConstruction : 0) | (IsPointerToTypeDerivedFromQObject::Value ? QMetaType::PointerToQObject : 0) | (IsSharedPointerToTypeDerivedFromQObject::Value ? QMetaType::SharedPointerToQObject : 0) | (IsWeakPointerToTypeDerivedFromQObject::Value ? QMetaType::WeakPointerToQObject : 0) @@ -2312,10 +2317,11 @@ class QMetaTypeForType { public: static constexpr decltype(typenameHelper()) name = typenameHelper(); + static constexpr unsigned Flags = QMetaTypeTypeFlags::Flags; static constexpr QMetaTypeInterface::DefaultCtrFn getDefaultCtr() { - if constexpr (std::is_default_constructible_v) { + if constexpr (std::is_default_constructible_v && !std::is_trivially_default_constructible_v) { return [](const QMetaTypeInterface *, void *addr) { new (addr) S(); }; } else { return nullptr; @@ -2324,7 +2330,7 @@ public: static constexpr QMetaTypeInterface::CopyCtrFn getCopyCtr() { - if constexpr (std::is_copy_constructible_v) { + if constexpr (std::is_copy_constructible_v && !std::is_trivially_copy_constructible_v) { return [](const QMetaTypeInterface *, void *addr, const void *other) { new (addr) S(*reinterpret_cast(other)); }; @@ -2335,7 +2341,7 @@ public: static constexpr QMetaTypeInterface::MoveCtrFn getMoveCtr() { - if constexpr (std::is_move_constructible_v) { + if constexpr (std::is_move_constructible_v && !std::is_trivially_move_constructible_v) { return [](const QMetaTypeInterface *, void *addr, void *other) { new (addr) S(std::move(*reinterpret_cast(other))); }; @@ -2386,7 +2392,7 @@ struct QMetaTypeInterfaceWrapper /*.revision=*/ 0, /*.alignment=*/ alignof(T), /*.size=*/ sizeof(T), - /*.flags=*/ QMetaTypeTypeFlags::Flags, + /*.flags=*/ QMetaTypeForType::Flags, /*.typeId=*/ BuiltinMetaType::value, /*.metaObjectFn=*/ MetaObjectForType::metaObjectFunction, /*.name=*/ QMetaTypeForType::getName(), -- cgit v1.2.3