[PATCH] D126458: [Support] Reduce allocations in parallelForEach with move

Andrew Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 02:31:17 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4290ef54e18a: [Support] Reduce allocations in parallelForEach with move (authored by andrewng).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126458/new/

https://reviews.llvm.org/D126458

Files:
  llvm/lib/Support/Parallel.cpp


Index: llvm/lib/Support/Parallel.cpp
===================================================================
--- llvm/lib/Support/Parallel.cpp
+++ llvm/lib/Support/Parallel.cpp
@@ -89,7 +89,7 @@
   void add(std::function<void()> F) override {
     {
       std::lock_guard<std::mutex> Lock(Mutex);
-      WorkStack.push(F);
+      WorkStack.push(std::move(F));
     }
     Cond.notify_one();
   }
@@ -102,7 +102,7 @@
       Cond.wait(Lock, [&] { return Stop || !WorkStack.empty(); });
       if (Stop)
         break;
-      auto Task = WorkStack.top();
+      auto Task = std::move(WorkStack.top());
       WorkStack.pop();
       Lock.unlock();
       Task();
@@ -161,7 +161,7 @@
 void TaskGroup::spawn(std::function<void()> F) {
   if (Parallel) {
     L.inc();
-    Executor::getDefaultExecutor()->add([&, F] {
+    Executor::getDefaultExecutor()->add([&, F = std::move(F)] {
       F();
       L.dec();
     });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126458.432502.patch
Type: text/x-patch
Size: 913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220527/f29023ad/attachment.bin>


More information about the llvm-commits mailing list