diff options
-rw-r--r-- | src/parser.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 85d455c..f05f167 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1024,9 +1024,18 @@ StateStart::custom(gchar chr) expressions.brace_close(); LoopStack::undo_push<loop_stack>(loop_stack.pop()); } else { - /* repeat loop */ + /* + * Repeat loop: + * NOTE: One undo token per iteration could + * be avoided by saving the original counter + * in the LoopContext. + * We do however optimize the case of infinite loops + * because the loop counter does not have to be + * updated. + */ macro_pc = ctx.pc; - ctx.counter = MAX(ctx.counter - 1, -1); + if (ctx.counter >= 0) + undo.push_var(ctx.counter) = ctx.counter - 1; } } break; |