[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

llvm-svn: 347620
This commit is contained in:
Fangrui Song 2018-11-27 00:26:50 +00:00
parent 3bd249018c
commit 41828e7e52
1 changed files with 1 additions and 1 deletions

View File

@ -74,7 +74,7 @@ template <typename R, class FuncTy> void parallelForEach(R &&Range, FuncTy Fn) {
}
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