From 1bd91e7e945a3b95e8f17ef0cd0c915f22c4192f Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 4 Jun 2021 15:12:01 -0700 Subject: [PATCH] JobSystem: simplify callback code we can use the lambda syntax instead of a static method. --- libs/utils/include/utils/JobSystem.h | 36 ++++++++++------------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/libs/utils/include/utils/JobSystem.h b/libs/utils/include/utils/JobSystem.h index 6193cf2e7f..98fc96dacf 100644 --- a/libs/utils/include/utils/JobSystem.h +++ b/libs/utils/include/utils/JobSystem.h @@ -169,12 +169,9 @@ public: // the caller must ensure the object will outlive the Job template Job* createJob(Job* parent, T* data) noexcept { - struct stub { - static void call(void* user, JobSystem& js, Job* job) noexcept { - (*static_cast(user)->*method)(js, job); - } - }; - Job* job = create(parent, &stub::call); + Job* job = create(parent, [](void* user, JobSystem& js, Job* job) { + (*static_cast(user)->*method)(js, job); + }); if (job) { job->storage[0] = data; } @@ -185,18 +182,14 @@ public: template Job* createJob(Job* parent, T data) noexcept { static_assert(sizeof(data) <= sizeof(Job::storage), "user data too large"); - struct stub { - static void call(void* user, JobSystem& js, Job* job) noexcept { - T* that = static_cast(user); - (that->*method)(js, job); - that->~T(); - } - }; - Job* job = create(parent, &stub::call); + Job* job = create(parent, [](void* user, JobSystem& js, Job* job) { + T* that = static_cast(user); + (that->*method)(js, job); + that->~T(); + }); if (job) { new(job->storage) T(std::move(data)); } - assert(job); return job; } @@ -204,14 +197,11 @@ public: template Job* createJob(Job* parent, T functor) noexcept { static_assert(sizeof(functor) <= sizeof(Job::storage), "functor too large"); - struct stub { - static void call(void* user, JobSystem& js, Job* job) noexcept { - T& that = *static_cast(user); - that(js, job); - that.~T(); - } - }; - Job* job = create(parent, &stub::call); + Job* job = create(parent, [](void* user, JobSystem& js, Job* job){ + T& that = *static_cast(user); + that(js, job); + that.~T(); + }); if (job) { new(job->storage) T(std::move(functor)); }