From b6d5d419cce1134a2e71723e4323ecfa2e70f13c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 4 May 2023 15:48:12 +0200 Subject: [PATCH] QObject: simplify ImplFns of Q(Private)SlotObjects Drag the cast out of each case to before the switch. DRYs the code. Pick-to: 6.5 Change-Id: I117cc5d38379a11e9852fba61794fa59dc24a30f Reviewed-by: Thiago Macieira Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qobject_p.h | 7 ++++--- src/corelib/kernel/qobjectdefs_impl.h | 9 +++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index d56e9aa60c..ef89786a4d 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -290,16 +290,17 @@ class QPrivateSlotObject : public QSlotObjectBase, private FunctionStorage typedef QtPrivate::FunctionPointer FuncType; static void impl(int which, QSlotObjectBase *this_, QObject *r, void **a, bool *ret) { + const auto that = static_cast(this_); switch (which) { case Destroy: - delete static_cast(this_); + delete that; break; case Call: - FuncType::template call(static_cast(this_)->func(), + FuncType::template call(that->func(), static_cast(QObjectPrivate::get(r)), a); break; case Compare: - *ret = *reinterpret_cast(a) == static_cast(this_)->func(); + *ret = *reinterpret_cast(a) == that->func(); break; case NumOperations: ; } diff --git a/src/corelib/kernel/qobjectdefs_impl.h b/src/corelib/kernel/qobjectdefs_impl.h index 41ef92b4aa..156a6d6c42 100644 --- a/src/corelib/kernel/qobjectdefs_impl.h +++ b/src/corelib/kernel/qobjectdefs_impl.h @@ -413,19 +413,20 @@ namespace QtPrivate { FunctorValue function; static void impl(int which, QSlotObjectBase *this_, QObject *r, void **a, bool *ret) { + const auto that = static_cast(this_); switch (which) { case Destroy: - delete static_cast(this_); + delete that; break; case Call: if constexpr (std::is_member_function_pointer_v) - FuncType::template call(static_cast(this_)->function, static_cast(r), a); + FuncType::template call(that->function, static_cast(r), a); else - FuncType::template call(static_cast(this_)->function, r, a); + FuncType::template call(that->function, r, a); break; case Compare: if constexpr (std::is_member_function_pointer_v) { - *ret = *reinterpret_cast(a) == static_cast(this_)->function; + *ret = *reinterpret_cast(a) == that->function; break; } // not implemented otherwise