mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user