From 0749d1fa3398e062b1e420d54c528803c34c8f55 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 16 Jul 2023 10:40:02 +0200 Subject: [PATCH] QMetaCallEvent::create(): re-order operations ... so that everything that requires argv is done first. Also introduce a new variable, argc, for sizeof...(Args) + 1. This will allow us to apply Extract Method to the tail end, which now no longer depends on argv or Args. As a drive-by, port from std::array to C arrays so we can use automatic array size deduction: There's still no such thing as partial CTAD (certainly not in C++17), so if we wanted std::array to deduce the size, we'd also need to let it deduce the type; and we don't want to add an ugly cast to the nullptr). C arrays, OTOH, can deduce the size while fixing the type since K&R C. Change-Id: I5a694d4f4d41974eb4b1075ff030bbef902ed492 Reviewed-by: Volker Hilsheimer (cherry picked from commit 74707948652d1b251b2296ce0b3a515b2ddbcc08) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qobject_p.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 66269b4c2ad..5fcf138b443 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -391,14 +391,15 @@ public: static QMetaCallEvent *create(QtPrivate::QSlotObjectBase *slotObj, const QObject *sender, int signal_index, const Args &...argv) { + const void* const argp[] = { nullptr, std::addressof(argv)... }; + const QMetaType metaTypes[] = { QMetaType::fromType(), QMetaType::fromType()... }; + constexpr auto argc = sizeof...(Args) + 1; auto metaCallEvent = std::make_unique(slotObj, sender, - signal_index, int(1 + sizeof...(Args))); + signal_index, int(argc)); void **args = metaCallEvent->args(); QMetaType *types = metaCallEvent->types(); - const std::array argp{ nullptr, std::addressof(argv)... }; - const std::array metaTypes{ QMetaType::fromType(), QMetaType::fromType()... }; - for (size_t i = 0; i < sizeof...(Args) + 1; ++i) { + for (size_t i = 0; i < argc; ++i) { types[i] = metaTypes[i]; args[i] = types[i].create(argp[i]); Q_CHECK_PTR(!i || args[i]);