From cf65fbe6a190cd05936e486fe75ad8a0859b2ed2 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 18 Oct 1989 09:22:47 +0000 Subject: [PATCH] a simple optimization added --- util/LLgen/src/gencode.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 35b32acc6..516294711 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -547,6 +547,19 @@ alternation(pp, safety, mustscan, mustpop, lb) if (unsafe && hulp1 == lb) { fprintf(f,"L_%d: \n", hulp1); } + if (safety == SAFE) { + /* check if we can avoid to generate the switch */ + for (;;) { + if (g_gettype(p) == EORULE) return; + l = g_getlink(p); + if (l->l_flag & COND) break; + if ((g_gettype(l->l_rule) != TERMINAL && + g_gettype(l->l_rule) != LITERAL) || + g_gettype(l->l_rule+1) != EORULE) break; + p++; + } + p = pp; + } while (g_gettype(p) != EORULE) { l = g_getlink(p); if (l->l_flag & COND) {