From b259cb68aa3f76d1e23b47be67d3fbeb6f6b62df Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 11 Feb 2016 13:09:39 +0100 Subject: optimized command execution in batch mode, during macro calls, loops etc. * SciTECO commands are implemented with immediate execution in mind. Those commands that do need to execute immediately while a string command is entered, can do so using StateExpectString::process(). For simplicity, the parser just assumed that every input character should result in immediate execution (if the command supports it of course). * This lead to unnecessarily slow execution of commands like or in batch mode. E.g. a search was always repeated for every character of the pattern - a N character pattern could result in N searches instead of one. Also in interactive mode when executing a macro or repeating commands in a loop, immediate processing of string arguments is unnecessary and results in superfluous undo tokens. * These cases are all optimized now by being informed about the necessity of providing immediate feedback via State::refresh(). This is used by StateExpectString to defer calling process() as long as possible. * For states extending StateExpectString, there is no change since they can already process arbitrarily long strings. The optimization is hidden in StateExpectString. * some allocations are now also avoided in StateExpectString::custom(). --- src/parser.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/parser.h') diff --git a/src/parser.h b/src/parser.h index 1cd51c7..a1bfd75 100644 --- a/src/parser.h +++ b/src/parser.h @@ -54,9 +54,20 @@ public: static void input(gchar chr); State *get_next_state(gchar chr); + /** + * Provide interactive feedback. + * + * This gets called whenever a state with + * immediate interactive feedback should provide that + * feedback; allowing them to optimize batch mode, + * macro and many other cases. + */ + virtual void refresh(void) {} + protected: static bool eval_colon(void); + /** Get next state given an input character */ virtual State * custom(gchar chr) { @@ -136,6 +147,7 @@ public: */ class StateExpectString : public State { StringBuildingMachine machine; + gsize insert_len; gint nesting; @@ -144,11 +156,12 @@ class StateExpectString : public State { public: StateExpectString(bool _building = true, bool _last = true) - : State(), nesting(1), + : insert_len(0), nesting(1), string_building(_building), last(_last) {} private: State *custom(gchar chr); + void refresh(void); protected: virtual void initial(void) {} -- cgit v1.2.3