From 8fa3789ade1ba2618dfb8e8e7c5bb0d1e1c9701a Mon Sep 17 00:00:00 2001 From: Lawrence Kesteloot Date: Sun, 5 Aug 2018 17:07:25 -0700 Subject: [PATCH] Slightly improve performance of NEXT. --- runtime.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime.c b/runtime.c index 2e2e45d..7d6aa02 100644 --- a/runtime.c +++ b/runtime.c @@ -381,13 +381,16 @@ static ForInfo *find_for_info(uint16_t var_address) { int i; ForInfo *f; - for (i = 0; i < g_for_count; i++) { - f = &g_for_info[i]; - + // Work backwards through the stack, since the variable we're looking + // for is likely to be the most recent one. + f = &g_for_info[g_for_count - 1]; + for (i = g_for_count - 1; i >= 0; i--) { if (f->var_address == var_address) { // Found it. return f; } + + f -= 1; } return 0;