[lld] r347620 - [Common] Threads: use function_ref instead of std::function
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 26 16:26:51 PST 2018
Author: maskray
Date: Mon Nov 26 16:26:50 2018
New Revision: 347620
URL: http://llvm.org/viewvc/llvm-project?rev=347620&view=rev
Log:
[Common] Threads: use function_ref instead of std::function
The benefits are:
a) Performance (very minor): it removes a heap allocation of the std::function constructor (template<class F> function(F f))
b) Clarity: it suggests that the callable's lifetime should end after the callee returns. Such callback is widely used in llvm. lld also uses it a lot.
Reviewers: ruiu, rnk, pcc
Reviewed By: ruiu
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D54813
Modified:
lld/trunk/include/lld/Common/Threads.h
Modified: lld/trunk/include/lld/Common/Threads.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Common/Threads.h?rev=347620&r1=347619&r2=347620&view=diff
==============================================================================
--- lld/trunk/include/lld/Common/Threads.h (original)
+++ lld/trunk/include/lld/Common/Threads.h Mon Nov 26 16:26:50 2018
@@ -74,7 +74,7 @@ template <typename R, class FuncTy> void
}
inline void parallelForEachN(size_t Begin, size_t End,
- std::function<void(size_t)> Fn) {
+ llvm::function_ref<void(size_t)> Fn) {
if (ThreadsEnabled)
for_each_n(llvm::parallel::par, Begin, End, Fn);
else
More information about the llvm-commits
mailing list