Commit 7ef79a5f authored by Marshall Cline's avatar Marshall Cline Committed by Facebook Github Bot

Perf improvement of folly::Future's map()

Summary: folly::Future's map() functions create a std::vector<Future<...>>, then use push_back to populate that vector. This could result in reallocations. Avoid that by reserving proper space ahead of the push_backs.

Reviewed By: yfeldblum

Differential Revision: D9204713

fbshipit-source-id: 51d9154f483a47c6196a4d4d9d4af14e4eeab6e0
parent f0939c67
......@@ -2306,6 +2306,7 @@ namespace futures {
template <class It, class F, class ItT, class Result>
std::vector<Future<Result>> map(It first, It last, F func) {
std::vector<Future<Result>> results;
results.reserve(std::distance(first, last));
for (auto it = first; it != last; it++) {
results.push_back(std::move(*it).then(func));
}
......@@ -2315,6 +2316,7 @@ std::vector<Future<Result>> map(It first, It last, F func) {
template <class It, class F, class ItT, class Result>
std::vector<Future<Result>> map(Executor& exec, It first, It last, F func) {
std::vector<Future<Result>> results;
results.reserve(std::distance(first, last));
for (auto it = first; it != last; it++) {
results.push_back(std::move(*it).via(&exec).then(func));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment