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

@@ -392,16 +392,14 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector<Symbol>
if (other) {
// The same symbol can only be defined twice if neither
// definition is in a floating section
auto visitor = Visitor{
[](int32_t value) -> std::tuple<Section *, int32_t> {
return {nullptr, value};
},
[](Label label) -> std::tuple<Section *, int32_t> {
return {label.section, label.offset};
},
auto checkSymbol = [](Symbol const &sym) -> std::tuple<Section *, int32_t> {
if (auto *label = std::get_if<Label>(&sym.data); label)
return {label->section, label->offset};
assert(std::holds_alternative<int32_t>(sym.data));
return {nullptr, std::get<int32_t>(sym.data)};
};
auto [symbolSection, symbolValue] = std::visit(visitor, symbol.data);
auto [otherSection, otherValue] = std::visit(visitor, other->data);
auto [symbolSection, symbolValue] = checkSymbol(symbol);
auto [otherSection, otherValue] = checkSymbol(*other);
if ((otherSection && !otherSection->isAddressFixed)
|| (symbolSection && !symbolSection->isAddressFixed)) {