From 813167be67449e62971b29af771df0408842c3ce Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Thu, 12 Mar 2015 21:49:55 +0000 Subject: [PATCH] Simplified codegen decision between switches/ifs. All tests pass. The previous condition made more sense: it was clear that the author intended to consider some frequent corner cases. But the condition was very tangled and yet too heuristic, so I substituted it with a meaningless, but simple one. I'm planning to simplify it even more later on. --- re2c/code.cc | 38 +++----------------------------------- 1 file changed, 3 insertions(+), 35 deletions(-) diff --git a/re2c/code.cc b/re2c/code.cc index 0055f193..a028f98c 100644 --- a/re2c/code.cc +++ b/re2c/code.cc @@ -821,45 +821,13 @@ static void genBase(OutputFile & o, uint ind, const State *from, const State *ne { if (nsp == 0) { - return ; + return; } - - if (!sFlag) + else if (!sFlag || (nsp > 8 && (sp[nsp - 2].ub - sp[0].ub <= 3 * (nsp - 2)))) { genSwitch(o, ind, from, next, readCh, sp, nsp); - return ; } - - if (nsp > 8) - { - Span *bot = &sp[0], *top = &sp[nsp - 1]; - uint util; - - // decide if IFs insted of SWITCHes is a good idea - if (bot[0].to == top[0].to) - { - util = (top[ -1].ub - bot[0].ub) / (nsp - 2); - } - else - { - if (bot[0].ub > (top[0].ub - top[ -1].ub)) - { - util = (top[0].ub - bot[0].ub) / (nsp - 1); - } - else - { - util = top[ -1].ub / (nsp - 1); - } - } - - if (util <= 2) - { - genSwitch(o, ind, from, next, readCh, sp, nsp); - return ; - } - } - - if (nsp > 5) + else if (nsp > 5) { doBinary(o, ind, sp, nsp, from, next, readCh); } -- 2.40.0