diff --git a/include/vcpkg/base/parallel-algorithms.h b/include/vcpkg/base/parallel-algorithms.h index a7215ad3a1..47b2472746 100644 --- a/include/vcpkg/base/parallel-algorithms.h +++ b/include/vcpkg/base/parallel-algorithms.h @@ -29,55 +29,55 @@ namespace vcpkg } } - template - void parallel_for_each_n(RanIt begin, size_t work_count, F cb) noexcept + template + void parallel_for_each(Container&& c, F cb) noexcept { - if (work_count == 0) + if (c.size() == 0) { return; } - if (work_count == 1) + if (c.size() == 1) { - cb(*begin); + cb(c[0]); return; } std::atomic_size_t next{0}; - execute_in_parallel(work_count, [&]() { + execute_in_parallel(c.size(), [&]() { size_t i = 0; - while (i < work_count) + while (i < c.size()) { if (next.compare_exchange_weak(i, i + 1, std::memory_order_relaxed)) { - cb(*(begin + i)); + cb(c[i]); } } }); } - template - void parallel_transform(RanItSource begin, size_t work_count, RanItTarget out_begin, F&& cb) noexcept + template + void parallel_transform(const Container& c, RanItTarget out_begin, F&& cb) noexcept { - if (work_count == 0) + if (c.size() == 0) { return; } - if (work_count == 1) + if (c.size() == 1) { - *out_begin = cb(*begin); + *out_begin = cb(c[0]); return; } std::atomic_size_t next{0}; - execute_in_parallel(work_count, [&]() { + execute_in_parallel(c.size(), [&]() { size_t i = 0; - while (i < work_count) + while (i < c.size()) { if (next.compare_exchange_weak(i, i + 1, std::memory_order_relaxed)) { - *(out_begin + i) = cb(*(begin + i)); + *(out_begin + i) = cb(c[i]); } } }); diff --git a/src/vcpkg/base/system.process.cpp b/src/vcpkg/base/system.process.cpp index 294c2e98fb..df72e80a30 100644 --- a/src/vcpkg/base/system.process.cpp +++ b/src/vcpkg/base/system.process.cpp @@ -676,7 +676,7 @@ namespace vcpkg { std::vector> res(cmd_lines.size(), LocalizedString{}); - parallel_transform(cmd_lines.begin(), cmd_lines.size(), res.begin(), [&](const Command& cmd_line) { + parallel_transform(cmd_lines, res.begin(), [&](const Command& cmd_line) { return cmd_execute_and_capture_output(cmd_line, wd, env); }); diff --git a/src/vcpkg/postbuildlint.cpp b/src/vcpkg/postbuildlint.cpp index a5b9f7db4d..9849db2436 100644 --- a/src/vcpkg/postbuildlint.cpp +++ b/src/vcpkg/postbuildlint.cpp @@ -1290,7 +1290,7 @@ namespace vcpkg std::mutex mtx; auto files = fs.get_regular_files_recursive(dir, IgnoreErrors{}); - parallel_for_each_n(files.begin(), files.size(), [&](const Path& file) { + parallel_for_each(files, [&](const Path& file) { if (file_contains_absolute_paths(fs, file, searcher_paths)) { std::lock_guard lock{mtx};