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:
@@ -61,21 +61,20 @@ static int32_t CallbackPC() {
|
||||
|
||||
int32_t Symbol::getValue() const {
|
||||
assert(std::holds_alternative<int32_t>(data) || std::holds_alternative<int32_t (*)()>(data));
|
||||
if (int32_t const *value = std::get_if<int32_t>(&data); value) {
|
||||
if (auto *value = std::get_if<int32_t>(&data); value) {
|
||||
return type == SYM_LABEL ? *value + getSection()->org : *value;
|
||||
}
|
||||
return getOutputValue();
|
||||
}
|
||||
|
||||
int32_t Symbol::getOutputValue() const {
|
||||
return std::visit(
|
||||
Visitor{
|
||||
[](int32_t value) -> int32_t { return value; },
|
||||
[](int32_t (*callback)()) -> int32_t { return callback(); },
|
||||
[](auto &) -> int32_t { return 0; },
|
||||
},
|
||||
data
|
||||
);
|
||||
if (auto *value = std::get_if<int32_t>(&data); value) {
|
||||
return *value;
|
||||
} else if (auto *callback = std::get_if<int32_t (*)()>(&data); callback) {
|
||||
return (*callback)();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
std::string_view *Symbol::getMacro() const {
|
||||
|
||||
Reference in New Issue
Block a user