mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Use a custom generic tagged union Either instead of std::variant for efficiency (#1476)
* Implement custom generic tagged union `Either` This should be more efficient than `std::variant`, while still keeping runtime safety as it `assert`s when `get`ting values. * Use `Either` for RPN expressions * Use `Either` for file stack node data * Use `Either` for `File` buffer * Use `Either` for `STRFMT` args * Use `Either` for RGBLINK symbol values * Support an equivalent of `std::monostate` for `Either` * Use `Either` for lexer tokens * Use `Either` for symbol values * Use `Either` for lexer mmap/buffer state
This commit is contained in:
@@ -564,16 +564,16 @@ static void writeSym() {
|
||||
constants.clear();
|
||||
sym_ForEach([](Symbol &sym) {
|
||||
// Symbols are already limited to the exported ones
|
||||
if (std::holds_alternative<int32_t>(sym.data))
|
||||
if (sym.data.holds<int32_t>())
|
||||
constants.push_back(&sym);
|
||||
});
|
||||
// Numeric constants are ordered by value, then by name
|
||||
std::sort(RANGE(constants), [](Symbol *sym1, Symbol *sym2) -> bool {
|
||||
int32_t val1 = std::get<int32_t>(sym1->data), val2 = std::get<int32_t>(sym2->data);
|
||||
int32_t val1 = sym1->data.get<int32_t>(), val2 = sym2->data.get<int32_t>();
|
||||
return val1 != val2 ? val1 < val2 : sym1->name < sym2->name;
|
||||
});
|
||||
for (Symbol *sym : constants) {
|
||||
int32_t val = std::get<int32_t>(sym->data);
|
||||
int32_t val = sym->data.get<int32_t>();
|
||||
int width = val < 0x100 ? 2 : val < 0x10000 ? 4 : 8;
|
||||
fprintf(symFile, "%0*" PRIx32 " %s\n", width, val, sym->name.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user