mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
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:
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user