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.

Pick-to: 6.6
Change-Id: I5a694d4f4d41974eb4b1075ff030bbef902ed492
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Marc Mutz 2023-07-16 10:40:02 +02:00 committed by Volker Hilsheimer
parent 65647d54b9
commit 7470794865
1 changed files with 5 additions and 4 deletions

View File

@ -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<void>(), QMetaType::fromType<Args>()... };
constexpr auto argc = sizeof...(Args) + 1;
auto metaCallEvent = std::make_unique<QMetaCallEvent>(slotObj, sender,
signal_index, int(1 + sizeof...(Args)));
signal_index, int(argc));
void **args = metaCallEvent->args();
QMetaType *types = metaCallEvent->types();
const std::array<const void *, sizeof...(Args) + 1> argp{ nullptr, std::addressof(argv)... };
const std::array metaTypes{ QMetaType::fromType<void>(), QMetaType::fromType<Args>()... };
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]);