From d762f869f2bc72a3d67e9daca49e7e807d773651 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sun, 1 Nov 2020 20:41:25 -0800 Subject: [PATCH] replace for loop with std::transform Seems to be a small performance boost with make test. Total Test time (real) = 5.17 sec vs Total Test time (real) = 5.11 sec Signed-off-by: Rosen Penev --- include/cxxopts.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index dd4f31e..929d822 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -2225,12 +2225,16 @@ void Options::generate_all_groups_help(String& result) const { std::vector all_groups; - all_groups.reserve(m_help.size()); - for (const auto& group : m_help) - { - all_groups.push_back(group.first); - } + std::transform( + m_help.begin(), + m_help.end(), + std::back_inserter(all_groups), + [] (const std::map::value_type& group) + { + return group.first; + } + ); generate_group_help(result, all_groups); }