From 1da5bdeb986657c5cfd83d495d15b7f2308d3b5b Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 10 Feb 2016 15:08:46 +0100 Subject: avoid unnecessary undo token allocations in batch mode: greatly speeds up batch mode * by using variadic templates, UndoStack::push() is now responsible for allocating undo tokens. This is avoided in batch mode. * The old UndoStack::push(UndoToken *) method has been made private to avoid confusion around UndoStack's API. The old UndoStack::push() no longer needs to handle !undo.enabled, but at least asserts on it. * C++11 support is now required, so variadic templates can be used. This could have also been done using manual undo.enabled checks; or using multiple versions of the template with different numbers of template arguments. The latter could be done if we one day have to support a non-C++11 compiler. However since we're depending on GCC 4.4, variadic template use should be OK. Clang supports it since v2.9. * Sometimes, undo token pushing passed ownership of some memory to the undo token. The old behaviour was relied on to reclaim the memory even in batch mode -- the undo token was always deleted. To avoid leaks or repeated manual undo.enabled checking, another method UndoStack::push_own() had to be introduced that makes sure that an undo token is always created. In batch mode (!undo.enabled), this will however create the object on the stack which is much cheaper than using `new`. * Having to know which kind of undo token is to be pushed (taking ownership or not) is inconvenient. It may be better to add static methods to the UndoToken classes that can take care of reclaiming memory. * Benchmarking certain SciTECO scripts have shown 50% (!!!) speed increases at the highest possible optimization level (-O3 -mtune=native -march=native). --- src/expressions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/expressions.h') diff --git a/src/expressions.h b/src/expressions.h index f969b67..216ec7a 100644 --- a/src/expressions.h +++ b/src/expressions.h @@ -111,7 +111,7 @@ public: inline void undo_push(Type value, guint index = 0) { - undo.push(new UndoTokenPush(this, value, index)); + undo.push(this, value, index); } inline Type @@ -132,7 +132,7 @@ public: inline void undo_pop(guint index = 0) { - undo.push(new UndoTokenPop(this, index)); + undo.push(this, index); } inline Type & -- cgit v1.2.3