From 42ff02585bcacae033bee129618e9e3db4f3ecdb Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Wed, 15 Sep 2021 17:21:04 +0200 Subject: [PATCH] parseaut: convert short numbers without strtoul() * spot/parseaut/scanaut.ll: One or two digits numbers can be safely converted to integer without risking overflow, so do that without calling strtoul(). This simple change halves the number of calls to strtoul() on the example automaton of issue #476. --- spot/parseaut/scanaut.ll | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spot/parseaut/scanaut.ll b/spot/parseaut/scanaut.ll index d4d053381..c1c4fb44f 100644 --- a/spot/parseaut/scanaut.ll +++ b/spot/parseaut/scanaut.ll @@ -189,6 +189,12 @@ identifier [[:alpha:]_][[:alnum:]_.-]* yylval->str = new std::string(yytext + 1, yyleng - 1); return token::ANAME; } + /* Handle short numbers without going through parse_int() for efficiency. */ + [0-9] yylval->num = *yytext - '0'; return token::INT; + [0-9][0-9] { + yylval->num = (yytext[0] * 10) + yytext[1] - '0' * 11; + return token::INT; + } [0-9]+ parse_int(); return token::INT; } @@ -204,6 +210,12 @@ identifier [[:alpha:]_][[:alnum:]_.-]* "Acceptance-Pairs:" return token::ACCPAIRS; "Acc-Sig:" return token::ACCSIG; "---" return token::ENDOFHEADER; + /* Handle short numbers without going through parse_int() for efficiency. */ + [0-9] yylval->num = *yytext - '0'; return token::INT; + [0-9][0-9] { + yylval->num = (yytext[0] * 10) + yytext[1] - '0' * 11; + return token::INT; + } [0-9]+ parse_int(); return token::INT; /* The start of any automaton is the end of this one. We do not try to detect LBTT automata, as that would