diff options
author | 2022-03-30 14:07:33 +0000 | |
---|---|---|
committer | 2022-04-05 12:49:09 +0000 | |
commit | 714328e2d2f64a5d3976f19e6ffa781c69e9f6de (patch) | |
tree | 97693939392e5fe30398b15c3cb8e1e66fde4d49 /cmdline | |
parent | 47eea60033fc45b762a41dbaeae41b3296182e76 (diff) |
ART: Minor cleanup in cmdline/.
Avoid `std::function<>` when dumping help.
Avoid `std::optional<>::value()` because it is specified as
throwing an exception and we do not use C++ exceptions in
ART. Use `std::optional<>::has_value()` instead of implicit
conversion to `bool`.
Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Change-Id: I7addd70b6a69dcaff7a03a829953ed476896bdc0
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/cmdline_parser.h | 8 | ||||
-rw-r--r-- | cmdline/detail/cmdline_parse_argument_detail.h | 29 |
2 files changed, 16 insertions, 21 deletions
diff --git a/cmdline/cmdline_parser.h b/cmdline/cmdline_parser.h index 5cdf446474..8685da295d 100644 --- a/cmdline/cmdline_parser.h +++ b/cmdline/cmdline_parser.h @@ -739,11 +739,11 @@ void CmdlineParser<TVariantMap, TVariantMapKey>::DumpHelp(VariableIndentationOut std::unordered_map<std::string, std::vector<detail::CmdlineParseArgumentAny*>> args; for (const std::unique_ptr<detail::CmdlineParseArgumentAny>& it : completed_arguments_) { auto cat = it->GetCategory(); - if (cat) { - if (args.find(cat.value()) == args.end()) { - args[cat.value()] = {}; + if (cat.has_value()) { + if (args.find(*cat) == args.end()) { + args[*cat] = {}; } - args.at(cat.value()).push_back(it.get()); + args.at(*cat).push_back(it.get()); } else { uncat.push_back(it.get()); } diff --git a/cmdline/detail/cmdline_parse_argument_detail.h b/cmdline/detail/cmdline_parse_argument_detail.h index 0bde57bbae..de0a588b96 100644 --- a/cmdline/detail/cmdline_parse_argument_detail.h +++ b/cmdline/detail/cmdline_parse_argument_detail.h @@ -149,14 +149,13 @@ struct CmdlineParserArgumentInfo { vios.Stream() << std::endl; for (auto cname : names_) { std::string_view name = cname; - auto& os = vios.Stream(); - // nblank gets captured by print_once, so needs to be declared here. - std::string_view nblank; - std::function<void()> print_once; if (using_blanks_) { - nblank = name.substr(0, name.find("_")); - print_once = [&]() { - os << nblank; + name = name.substr(0, name.find("_")); + } + auto& os = vios.Stream(); + auto print_once = [&]() { + os << name; + if (using_blanks_) { if (has_value_map_) { bool first = true; for (auto [val, unused] : value_map_) { @@ -164,17 +163,13 @@ struct CmdlineParserArgumentInfo { first = false; } os << "}"; - } else if (metavar_) { - os << metavar_.value(); + } else if (metavar_.has_value()) { + os << *metavar_; } else { os << "{" << CmdlineType<T>::DescribeType() << "}"; } - }; - } else { - print_once = [&]() { - os << name; - }; - } + } + }; print_once(); if (appending_values_) { os << " ["; @@ -183,9 +178,9 @@ struct CmdlineParserArgumentInfo { } os << std::endl; } - if (help_) { + if (help_.has_value()) { ScopedIndentation si(&vios); - vios.Stream() << help_.value() << std::endl; + vios.Stream() << *help_ << std::endl; } } |