diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-11-22 16:47:09 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-11-22 18:15:21 +0100 |
commit | af05d382f26c828a45ba39044cf4e514c0fe9cc6 (patch) | |
tree | b4c034401e3c6d33b66b2d5ff1a00cd55f7793c4 /src | |
parent | 813d9b95d2f59d9a2702e2287f8f6965ba1bbf53 (diff) | |
download | sciteco-af05d382f26c828a45ba39044cf4e514c0fe9cc6.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/qregisters.cpp | 33 | ||||
-rw-r--r-- | src/qregisters.h | 35 |
2 files changed, 47 insertions, 21 deletions
diff --git a/src/qregisters.cpp b/src/qregisters.cpp index 19590c9..7d18910 100644 --- a/src/qregisters.cpp +++ b/src/qregisters.cpp @@ -697,6 +697,39 @@ QRegisterClipboard::undo_exchange_string(QRegisterData ®) } void +QRegisterTable::UndoTokenRemoveGlobal::run(void) +{ + delete (QRegister *)QRegisters::globals.remove(reg); +} + +void +QRegisterTable::UndoTokenRemoveLocal::run(void) +{ + /* + * NOTE: QRegisters::locals should point + * to the correct table when the token is + * executed. + */ + delete (QRegister *)QRegisters::locals->remove(reg); +} + +void +QRegisterTable::undo_remove(QRegister *reg) +{ + if (!must_undo) + return; + + /* + * NOTE: Could also be solved using a virtual + * method and subclasses... + */ + if (this == &QRegisters::globals) + undo.push<UndoTokenRemoveGlobal>(reg); + else + undo.push<UndoTokenRemoveLocal>(reg); +} + +void QRegisterTable::insert_defaults(void) { /* general purpose registers */ 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<UndoTokenRemove>(this, reg); - } + void undo_remove(QRegister *reg); inline QRegister * insert(QRegister *reg) |