================ @@ -642,26 +652,86 @@ ModuleSP DynamicLoaderDarwin::GetDYLDModule() { void DynamicLoaderDarwin::ClearDYLDModule() { m_dyld_module_wp.reset(); } +template <typename InputIterator, typename ResultType> +static std::vector<ResultType> parallel_map( + llvm::ThreadPoolInterface &threadPool, InputIterator first, + InputIterator last, + llvm::function_ref<ResultType( + const typename std::iterator_traits<InputIterator>::value_type &)> + transform) { + const auto size = std::distance(first, last); + std::vector<ResultType> results(size); + if (size > 0) { + llvm::ThreadPoolTaskGroup taskGroup(threadPool); + auto it = first; + for (ssize_t i = 0; i < size; ++i, ++it) { + taskGroup.async([&, i, it]() { results[i] = transform(*it); }); + } + taskGroup.wait(); + } + return results; +} ---------------- JDevlieghere wrote:
I personally think the new code, even with the little bit of code duplication, reads a lot easier than the templated signature of the `(parallel_)map` functions. I personally wouldn't bother with the `size > 0` check (I expect that creating an empty task group and waiting on an empty task group is essentially free). Anyway, I don't feel super strongly about it, so go with whatever you think is best. FWIW I don't expect us to ever migrate this code to `std::transform` because we definitely want to limit the parallelism by using the debugger's thread pool. https://github.com/llvm/llvm-project/pull/110646 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits