mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12: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:
@@ -19,11 +19,6 @@
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
int32_t Expression::value() const {
|
||||
assume(std::holds_alternative<int32_t>(data));
|
||||
return std::get<int32_t>(data);
|
||||
}
|
||||
|
||||
void Expression::clear() {
|
||||
data = 0;
|
||||
isSymbol = false;
|
||||
@@ -44,7 +39,7 @@ uint8_t *Expression::reserveSpace(uint32_t size, uint32_t patchSize) {
|
||||
|
||||
int32_t Expression::getConstVal() const {
|
||||
if (!isKnown()) {
|
||||
error("Expected constant expression: %s\n", std::get<std::string>(data).c_str());
|
||||
error("Expected constant expression: %s\n", data.get<std::string>().c_str());
|
||||
return 0;
|
||||
}
|
||||
return value();
|
||||
|
||||
Reference in New Issue
Block a user