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 <volker.hilsheimer@qt.io>
(cherry picked from commit 74707948652d1b251b2296ce0b3a515b2ddbcc08)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-07-16 10:40:02 +02:00 committed by Qt Cherry-pick Bot
parent 22d8539016
commit 0749d1fa33

View File

@ -391,14 +391,15 @@ public:
static QMetaCallEvent *create(QtPrivate::QSlotObjectBase *slotObj, const QObject *sender, static QMetaCallEvent *create(QtPrivate::QSlotObjectBase *slotObj, const QObject *sender,
int signal_index, const Args &...argv) int signal_index, const Args &...argv)
{ {
const void* const argp[] = { nullptr, std::addressof(argv)... };
const QMetaType metaTypes[] = { QMetaType::fromType<void>(), QMetaType::fromType<Args>()... };
constexpr auto argc = sizeof...(Args) + 1;
auto metaCallEvent = std::make_unique<QMetaCallEvent>(slotObj, sender, auto metaCallEvent = std::make_unique<QMetaCallEvent>(slotObj, sender,
signal_index, int(1 + sizeof...(Args))); signal_index, int(argc));
void **args = metaCallEvent->args(); void **args = metaCallEvent->args();
QMetaType *types = metaCallEvent->types(); QMetaType *types = metaCallEvent->types();
const std::array<const void *, sizeof...(Args) + 1> argp{ nullptr, std::addressof(argv)... }; for (size_t i = 0; i < argc; ++i) {
const std::array metaTypes{ QMetaType::fromType<void>(), QMetaType::fromType<Args>()... };
for (size_t i = 0; i < sizeof...(Args) + 1; ++i) {
types[i] = metaTypes[i]; types[i] = metaTypes[i];
args[i] = types[i].create(argp[i]); args[i] = types[i].create(argp[i]);
Q_CHECK_PTR(!i || args[i]); Q_CHECK_PTR(!i || args[i]);