]> granicus.if.org Git - re2c/commitdiff
Simplified codegen decision between switches/ifs.
authorUlya Trofimovich <skvadrik@gmail.com>
Thu, 12 Mar 2015 21:49:55 +0000 (21:49 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Thu, 12 Mar 2015 21:49:55 +0000 (21:49 +0000)
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

index 0055f19367530997fb8f5879bf0c76fd8c6b75c8..a028f98c31540e544d37cb5eea0955769a01bbcb 100644 (file)
@@ -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);
        }