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 <thiago.macieira@intel.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Marc Mutz 2023-05-04 15:48:12 +02:00
parent 3c4743c66c
commit b6d5d419cc
2 changed files with 9 additions and 7 deletions

View File

@ -290,16 +290,17 @@ class QPrivateSlotObject : public QSlotObjectBase, private FunctionStorage<Func>
typedef QtPrivate::FunctionPointer<Func> FuncType;
static void impl(int which, QSlotObjectBase *this_, QObject *r, void **a, bool *ret)
{
const auto that = static_cast<QPrivateSlotObject*>(this_);
switch (which) {
case Destroy:
delete static_cast<QPrivateSlotObject*>(this_);
delete that;
break;
case Call:
FuncType::template call<Args, R>(static_cast<QPrivateSlotObject*>(this_)->func(),
FuncType::template call<Args, R>(that->func(),
static_cast<typename FuncType::Object *>(QObjectPrivate::get(r)), a);
break;
case Compare:
*ret = *reinterpret_cast<Func *>(a) == static_cast<QPrivateSlotObject*>(this_)->func();
*ret = *reinterpret_cast<Func *>(a) == that->func();
break;
case NumOperations: ;
}

View File

@ -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<QFunctorSlotObject*>(this_);
switch (which) {
case Destroy:
delete static_cast<QFunctorSlotObject*>(this_);
delete that;
break;
case Call:
if constexpr (std::is_member_function_pointer_v<FunctorValue>)
FuncType::template call<Args, R>(static_cast<QFunctorSlotObject*>(this_)->function, static_cast<typename FuncType::Object *>(r), a);
FuncType::template call<Args, R>(that->function, static_cast<typename FuncType::Object *>(r), a);
else
FuncType::template call<Args, R>(static_cast<QFunctorSlotObject*>(this_)->function, r, a);
FuncType::template call<Args, R>(that->function, r, a);
break;
case Compare:
if constexpr (std::is_member_function_pointer_v<FunctorValue>) {
*ret = *reinterpret_cast<FunctorValue *>(a) == static_cast<QFunctorSlotObject*>(this_)->function;
*ret = *reinterpret_cast<FunctorValue *>(a) == that->function;
break;
}
// not implemented otherwise