Skip to content

Commit

Permalink
Clara::Opt::getHelpColumns returns single item
Browse files Browse the repository at this point in the history
It could never return multiple items, but for some reason it was
wrapping that single item in a vector.

This change ends up removing a significant (~150) number of
allocations when Catch2 has to collate the output for `-h`.
  • Loading branch information
horenmar committed Dec 26, 2023
1 parent 2295d2c commit 8596ab3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/catch2/internal/catch_clara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ namespace Catch {
Opt::Opt(bool& ref) :
ParserRefImpl(std::make_shared<Detail::BoundFlagRef>(ref)) {}

std::vector<Detail::HelpColumns> Opt::getHelpColumns() const {
Detail::HelpColumns Opt::getHelpColumns() const {
std::ostringstream oss;
bool first = true;
for (auto const& opt : m_optNames) {
Expand All @@ -185,7 +185,7 @@ namespace Catch {
}
if (!m_hint.empty())
oss << " <" << m_hint << '>';
return { { oss.str(), static_cast<std::string>(m_description) } };
return { oss.str(), static_cast<std::string>(m_description) };
}

bool Opt::isMatch(std::string const& optToken) const {
Expand Down Expand Up @@ -311,8 +311,7 @@ namespace Catch {
std::vector<Detail::HelpColumns> Parser::getHelpColumns() const {
std::vector<Detail::HelpColumns> cols;
for ( auto const& o : m_options ) {
auto childCols = o.getHelpColumns();
cols.insert( cols.end(), childCols.begin(), childCols.end() );
cols.push_back(o.getHelpColumns());
}
return cols;
}
Expand Down
2 changes: 1 addition & 1 deletion src/catch2/internal/catch_clara.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ namespace Catch {
return *this;
}

std::vector<Detail::HelpColumns> getHelpColumns() const;
Detail::HelpColumns getHelpColumns() const;

bool isMatch(std::string const& optToken) const;

Expand Down

0 comments on commit 8596ab3

Please sign in to comment.