From ab576d641d9ae77662e6e54a5db7fbe6d215fa6d Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Thu, 17 Oct 2024 11:04:23 -0700 Subject: [PATCH] reduce copies Summary: using move instead Reviewed By: Gownta Differential Revision: D63436308 fbshipit-source-id: f03dd93565663b3955019c0162344925fbacc286 --- folly/executors/CPUThreadPoolExecutor.cpp | 17 ++++++----------- folly/executors/GlobalThreadPoolList.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/folly/executors/CPUThreadPoolExecutor.cpp b/folly/executors/CPUThreadPoolExecutor.cpp index ddf47e131fb..0761fc00b58 100644 --- a/folly/executors/CPUThreadPoolExecutor.cpp +++ b/folly/executors/CPUThreadPoolExecutor.cpp @@ -98,7 +98,7 @@ CPUThreadPoolExecutor::CPUThreadPoolExecutor( Options opt) : ThreadPoolExecutor( numThreads.first, numThreads.second, std::move(threadFactory)), - taskQueue_(taskQueue.release()), + taskQueue_(std::move(taskQueue)), prohibitBlockingOnThreadPools_{opt.blocking} { setNumThreads(numThreads.first); if (numThreads.second == 0) { @@ -121,16 +121,11 @@ CPUThreadPoolExecutor::CPUThreadPoolExecutor( std::pair numThreads, std::shared_ptr threadFactory, Options opt) - : ThreadPoolExecutor( - numThreads.first, numThreads.second, std::move(threadFactory)), - taskQueue_(makeDefaultQueue()), - prohibitBlockingOnThreadPools_{opt.blocking} { - setNumThreads(numThreads.first); - if (numThreads.second == 0) { - minThreads_.store(1, std::memory_order_relaxed); - } - registerThreadPoolExecutor(this); -} + : CPUThreadPoolExecutor( + numThreads, + makeDefaultQueue(), + std::move(threadFactory), + std::move(opt)) {} CPUThreadPoolExecutor::CPUThreadPoolExecutor(size_t numThreads, Options opt) : CPUThreadPoolExecutor( diff --git a/folly/executors/GlobalThreadPoolList.cpp b/folly/executors/GlobalThreadPoolList.cpp index fa6dbe588d2..34b8c641e06 100644 --- a/folly/executors/GlobalThreadPoolList.cpp +++ b/folly/executors/GlobalThreadPoolList.cpp @@ -129,7 +129,7 @@ GlobalThreadPoolList& GlobalThreadPoolList::instance() { void GlobalThreadPoolList::registerThreadPool( ThreadPoolListHook* threadPoolId, std::string name) { - globalListImpl_.wlock()->registerThreadPool(threadPoolId, name); + globalListImpl_.wlock()->registerThreadPool(threadPoolId, std::move(name)); } void GlobalThreadPoolList::unregisterThreadPool( @@ -159,9 +159,9 @@ void GlobalThreadPoolList::unregisterThreadPoolThread( void GlobalThreadPoolListImpl::registerThreadPool( ThreadPoolListHook* threadPoolId, std::string name) { PoolInfo info; - info.name = name; + info.name = std::move(name); info.addr = threadPoolId; - pools_.vector().push_back(info); + pools_.vector().push_back(std::move(info)); } void GlobalThreadPoolListImpl::unregisterThreadPool( @@ -225,7 +225,7 @@ ThreadListHook::~ThreadListHook() { ThreadPoolListHook::ThreadPoolListHook(std::string name) { debugger_detail::GlobalThreadPoolList::instance().registerThreadPool( - this, name); + this, std::move(name)); } ThreadPoolListHook::~ThreadPoolListHook() {