From af05d382f26c828a45ba39044cf4e514c0fe9cc6 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 22 Nov 2016 16:47:09 +0100 Subject: save some bytes per Q-Register creation on the undo stack * a table reference was stored in the UndoToken. * since there are only two tables at a given moment, this can be avoided by having two different undo tokens, one for globals and one for locals. * Practically, undo tokens for locals are only created for the top-level local Q-Reg table since macro calls with locals with set must_undo to false since the local table is destroyed with the macro return. --- src/qregisters.h | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'src/qregisters.h') diff --git a/src/qregisters.h b/src/qregisters.h index fc7a624..d40a19b 100644 --- a/src/qregisters.h +++ b/src/qregisters.h @@ -285,25 +285,23 @@ public: }; class QRegisterTable : private RBTreeString, public Object { - class UndoTokenRemove : public UndoToken { - /* - * NOTE: Storing the table here is only necessary since - * we may have to remove from a global or local Q-Reg - * table. This could be avoided using a separate - * subclass for local registers. - */ - QRegisterTable *table; + class UndoTokenRemoveGlobal : public UndoToken { + protected: QRegister *reg; public: - UndoTokenRemove(QRegisterTable *_table, QRegister *_reg) - : table(_table), reg(_reg) {} + UndoTokenRemoveGlobal(QRegister *_reg) + : reg(_reg) {} - void - run(void) - { - delete (QRegister *)table->remove(reg); - } + void run(void); + }; + + class UndoTokenRemoveLocal : public UndoTokenRemoveGlobal { + public: + UndoTokenRemoveLocal(QRegister *reg) + : UndoTokenRemoveGlobal(reg) {} + + void run(void); }; bool must_undo; @@ -320,12 +318,7 @@ public: delete (QRegister *)remove(cur); } - inline void - undo_remove(QRegister *reg) - { - if (must_undo) - undo.push(this, reg); - } + void undo_remove(QRegister *reg); inline QRegister * insert(QRegister *reg) -- cgit v1.2.3