From b0edec353e7dab39e6aadc8cab947e1a1bf1c932 Mon Sep 17 00:00:00 2001 From: whd <7058128+superwhd@users.noreply.github.com> Date: Tue, 26 Jul 2022 11:02:55 +0800 Subject: [task-runner] fix `std::move` on const values (#1474) There is an issue in `TaskRunner` that it declares `Task` as a const parameter in interfaces (e.g. `void TaskRunner::Post(const Task aTask)`). In the implementation it `std::move`s the `aTask` and pushed it into an STL container. This `std::move` on the const value doesn't lead to the move constructor of `Task` which may have better performance. It leads to the copy constructor instead. To fix this, we need to make the `aTask` a non-const parameter. --- src/common/task_runner.cpp | 6 +++--- src/common/task_runner.hpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/common/task_runner.cpp b/src/common/task_runner.cpp index 75a0cb56..4ee0328d 100644 --- a/src/common/task_runner.cpp +++ b/src/common/task_runner.cpp @@ -70,12 +70,12 @@ TaskRunner::~TaskRunner(void) } } -void TaskRunner::Post(const Task aTask) +void TaskRunner::Post(Task aTask) { Post(Milliseconds::zero(), std::move(aTask)); } -void TaskRunner::Post(Milliseconds aDelay, const Task aTask) +void TaskRunner::Post(Milliseconds aDelay, Task aTask) { PushTask(aDelay, std::move(aTask)); } @@ -129,7 +129,7 @@ void TaskRunner::Process(const MainloopContext &aMainloop) PopTasks(); } -void TaskRunner::PushTask(Milliseconds aDelay, const Task aTask) +void TaskRunner::PushTask(Milliseconds aDelay, Task aTask) { ssize_t rval; const uint8_t kOne = 1; diff --git a/src/common/task_runner.hpp b/src/common/task_runner.hpp index f9a9a730..fe81e9c1 100644 --- a/src/common/task_runner.hpp +++ b/src/common/task_runner.hpp @@ -83,7 +83,7 @@ public: * @param[in] aTask The task to be executed. * */ - void Post(const Task aTask); + void Post(Task aTask); /** * This method posts a task to the task runner and returns immediately. @@ -94,7 +94,7 @@ public: * @param[in] aTask The task to be executed. * */ - void Post(Milliseconds aDelay, const Task aTask); + void Post(Milliseconds aDelay, Task aTask); /** * This method posts a task and waits for the completion of the task. @@ -154,7 +154,7 @@ private: Task mTask; }; - void PushTask(Milliseconds aDelay, const Task aTask); + void PushTask(Milliseconds aDelay, Task aTask); void PopTasks(void); // The event fds which are used to wakeup the mainloop -- cgit v1.2.3