Use std::get_if instead of std::visit (#1367)

`std::visit` is (arguably) cleaner code, but older versions of gcc
and clang (not very old; the ones packaged with Ubuntu 22.04 LTS)
compile them as tables of function pointers, instead of efficient
jump tables.
This commit is contained in:
Sylvie
2024-03-20 22:37:54 -04:00
committed by GitHub
parent 035678d250
commit 0af1e512c2
10 changed files with 167 additions and 217 deletions

View File

@@ -2689,14 +2689,12 @@ static std::string strfmt(
} else if (argIndex >= args.size()) {
// Will warn after formatting is done.
str += '%';
} else if (auto *n = std::get_if<uint32_t>(&args[argIndex]); n) {
str.append(fmt.formatNumber(*n));
} else {
str.append(std::visit(
Visitor{
[&fmt](uint32_t n) { return fmt.formatNumber(n); },
[&fmt](std::string const &s) { return fmt.formatString(s); },
},
args[argIndex]
));
assert(std::holds_alternative<std::string>(args[argIndex]));
auto &s = std::get<std::string>(args[argIndex]);
str.append(fmt.formatString(s));
}
argIndex++;