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

@@ -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 {