QGenericRunnable: remove common prefix from nested classes

Helps keep the code fit into line length limitations.

Change-Id: I2e861c6f0a991cc36991572c4386040b8e11ca40
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2023-05-04 17:49:01 +02:00
parent acd675c38c
commit 5ddfa8bbe6

View File

@ -42,31 +42,30 @@ private:
class QGenericRunnable : public QRunnable class QGenericRunnable : public QRunnable
{ {
// Type erasure, to only instantiate a non-virtual class per Callable: // Type erasure, to only instantiate a non-virtual class per Callable:
class QGenericRunnableHelperBase class HelperBase
{ {
protected: protected:
enum class Op { enum class Op {
Run, Run,
Destroy, Destroy,
}; };
using OpFn = void* (*)(Op, QGenericRunnableHelperBase *, void*); using OpFn = void* (*)(Op, HelperBase *, void*);
OpFn fn; OpFn fn;
protected: protected:
constexpr explicit QGenericRunnableHelperBase(OpFn f) noexcept : fn(f) {} constexpr explicit HelperBase(OpFn f) noexcept : fn(f) {}
~QGenericRunnableHelperBase() = default; ~HelperBase() = default;
public: public:
void run() { fn(Op::Run, this, nullptr); } void run() { fn(Op::Run, this, nullptr); }
void destroy() { fn(Op::Destroy, this, nullptr); } void destroy() { fn(Op::Destroy, this, nullptr); }
}; };
template <typename Callable> template <typename Callable>
class QGenericRunnableHelper : public QGenericRunnableHelperBase, class Helper : public HelperBase, private QtPrivate::CompactStorage<Callable>
private QtPrivate::CompactStorage<Callable>
{ {
using Storage = QtPrivate::CompactStorage<Callable>; using Storage = QtPrivate::CompactStorage<Callable>;
static void *impl(Op op, QGenericRunnableHelperBase *that, [[maybe_unused]] void *arg) static void *impl(Op op, HelperBase *that, [[maybe_unused]] void *arg)
{ {
const auto _this = static_cast<QGenericRunnableHelper*>(that); const auto _this = static_cast<Helper*>(that);
switch (op) { switch (op) {
case Op::Run: _this->object()(); break; case Op::Run: _this->object()(); break;
case Op::Destroy: delete _this; break; case Op::Destroy: delete _this; break;
@ -75,18 +74,18 @@ class QGenericRunnable : public QRunnable
} }
public: public:
template <typename UniCallable> template <typename UniCallable>
explicit QGenericRunnableHelper(UniCallable &&functionToRun) noexcept explicit Helper(UniCallable &&functionToRun) noexcept
: QGenericRunnableHelperBase(&impl), : HelperBase(&impl),
Storage{std::forward<UniCallable>(functionToRun)} Storage{std::forward<UniCallable>(functionToRun)}
{ {
} }
}; };
QGenericRunnableHelperBase *runHelper; HelperBase *runHelper;
public: public:
template <typename Callable, if_callable<Callable> = true> template <typename Callable, if_callable<Callable> = true>
explicit QGenericRunnable(Callable &&c) explicit QGenericRunnable(Callable &&c)
: runHelper(new QGenericRunnableHelper<std::decay_t<Callable>>(std::forward<Callable>(c))) : runHelper(new Helper<std::decay_t<Callable>>(std::forward<Callable>(c)))
{ {
} }
~QGenericRunnable() override ~QGenericRunnable() override