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

@@ -218,7 +218,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
);
isError = true;
value = 1;
} else if (Label const *label = std::get_if<Label>(&symbol->data); label) {
} else if (auto *label = std::get_if<Label>(&symbol->data); label) {
value = label->section->bank;
} else {
error(
@@ -383,16 +383,11 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
fileSymbols[value].name.c_str()
);
isError = true;
} else if (auto *label = std::get_if<Label>(&symbol->data); label) {
value = label->section->org + label->offset;
} else {
value = std::visit(
Visitor{
[](int32_t val) -> int32_t { return val; },
[](Label label) -> int32_t {
return label.section->org + label.offset;
},
},
symbol->data
);
assert(std::holds_alternative<int32_t>(symbol->data));
value = std::get<int32_t>(symbol->data);
}
}
break;