From 74136ba96f20f38af484ed96a6bec54d5fc9cdf6 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 4 Dec 2015 14:31:46 -0500 Subject: [PATCH] nitcc: generate a faster DFA::trans sequence of `if` Signed-off-by: Jean Privat --- contrib/nitcc/src/autom.nit | 7 +++++++ lib/json/json_lexer.nit | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/contrib/nitcc/src/autom.nit b/contrib/nitcc/src/autom.nit index 5b545b8..84df722 100644 --- a/contrib/nitcc/src/autom.nit +++ b/contrib/nitcc/src/autom.nit @@ -750,6 +750,13 @@ private class DFAGenerator end # Generate a sequence of `if` for the dispatch + if haslast != null then + # Special case: handle up-bound first if not an error + add("\t\tif c > {last} then return dfastate_{names[haslast]}\n") + # previous become the new last case + haslast = dispatch[last] + dispatch.keys.remove(last) + end for c, next in dispatch do if next == null then add("\t\tif c <= {c} then return null\n") diff --git a/lib/json/json_lexer.nit b/lib/json/json_lexer.nit index 4a54598..8ec28ff 100644 --- a/lib/json/json_lexer.nit +++ b/lib/json/json_lexer.nit @@ -97,11 +97,11 @@ private class DFAState2 super DFAState redef fun trans(char) do var c = char.code_point + if c > 92 then return dfastate_2 if c <= 33 then return dfastate_2 if c <= 34 then return dfastate_29 if c <= 91 then return dfastate_2 - if c <= 92 then return dfastate_30 - return dfastate_2 + return dfastate_30 end end private class DFAState3 -- 1.7.9.5