From 51e0a33a54968ddac179aa376cef4af73dd972af Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 18 Apr 2024 16:24:07 +0200 Subject: [PATCH] QSignalSpy: de-inline most of the private ctor ... by moving its body into an out-of-line init() function. This allows to drop the exporting of connectToSignal(). We can't de-inline the whole ctor (yet), because that would pin the vtable to the qsignalspy.cpp TU, which would require us to export the class wholesale to make the vtable accessible to users of the class, but we can't export the class because it inherits QList. Task-number: QTBUG-123544 Change-Id: Ieffd6d2f542daa20e876c6114cb5dc8150870bb4 Reviewed-by: David Faure Reviewed-by: Ahmad Samir --- src/testlib/qsignalspy.cpp | 11 +++++++++++ src/testlib/qsignalspy.h | 12 +++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/testlib/qsignalspy.cpp b/src/testlib/qsignalspy.cpp index 78eb14e6d8..3f06a09deb 100644 --- a/src/testlib/qsignalspy.cpp +++ b/src/testlib/qsignalspy.cpp @@ -244,6 +244,17 @@ QList QSignalSpy::makeArgs(const QMetaMethod &member, const QObject *obj) return result; } +void QSignalSpy::init(ObjectSignal os) +{ + if (!os.obj) + return; + + if (!connectToSignal(os.obj, os.sig.methodIndex())) + return; + + sig = os.sig.methodSignature(); +} + bool QSignalSpy::connectToSignal(const QObject *sender, int sigIndex) { static const int memberOffset = QObject::staticMetaObject.methodCount(); diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h index 5f52c1dcdf..3fc6d9483a 100644 --- a/src/testlib/qsignalspy.h +++ b/src/testlib/qsignalspy.h @@ -65,20 +65,14 @@ private: explicit QSignalSpy(ObjectSignal os) : args(os.obj ? makeArgs(os.sig, os.obj) : QList{}) { - if (!os.obj) - return; - - if (!connectToSignal(os.obj, os.sig.methodIndex())) - return; - - sig = os.sig.methodSignature(); + init(os); } - + Q_TESTLIB_EXPORT void init(ObjectSignal os); Q_TESTLIB_EXPORT static ObjectSignal verify(const QObject *obj, QMetaMethod signal); Q_TESTLIB_EXPORT static ObjectSignal verify(const QObject *obj, const char *aSignal); - Q_TESTLIB_EXPORT bool connectToSignal(const QObject *sender, int sigIndex); + bool connectToSignal(const QObject *sender, int sigIndex); Q_TESTLIB_EXPORT static QList makeArgs(const QMetaMethod &member, const QObject *obj); Q_TESTLIB_EXPORT void appendArgs(void **a);