From 9ec5e89c859b70b03a65ff773f8f85eddc277f71 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 24 Jun 2021 07:47:48 -0700 Subject: parser: no string allocation when scanning floats. Each time the scanner processes a floating-point token, it allocates a string object, just so it can call flo_str. The object is then garbage. Let's stop doing that. * lib.c (flo_str_utf8): New function, closely based on flo_str. Takes a char * string. * lib.h (flo_str_utf8): Declared. * parser.l (out_of_range_float): Take the token as a const char * string instead of a Lisp string, so we can just pass yytext to this function. (grammar): Use flo_str_utf8 instead flo_str, and pass yytext to out_of_range_float. * lex.yy.c.shipped: Updated. --- parser.l | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index ce3a5573..02465e26 100644 --- a/parser.l +++ b/parser.l @@ -130,10 +130,10 @@ static void yyerrprepf(scanner_t *scanner, val fmt, ...) } } -static void out_of_range_float(scanner_t *scanner, val tok) +static void out_of_range_float(scanner_t *scanner, const char *tok) { yyerrorf(scanner, lit("out-of-range floating-point literal: ~a"), - tok, nao); + string_utf8(tok), nao); } static wchar_t char_esc(int letter) @@ -343,15 +343,13 @@ NJPUNC [^(){},:\[\]"~*^ \t\n] } {WS}{FLO} { - val str = string_own(utf8_dup_from(yytext)); - if (yy_top_state(yyscanner) == INITIAL || yy_top_state(yyscanner) == QSILIT || yy_top_state(yyscanner) == QWLIT) yy_pop_state(yyscanner); - if ((yylval->val = flo_str(str)) == nil) - out_of_range_float(yyg, str); + if ((yylval->val = flo_str_utf8(yytext)) == nil) + out_of_range_float(yyg, yytext); return NUMBER; } @@ -368,22 +366,20 @@ NJPUNC [^(){},:\[\]"~*^ \t\n] || yy_top_state(yyscanner) == QWLIT) yy_pop_state(yyscanner); - if ((yylval->val = flo_str(str)) == nil) - out_of_range_float(yyg, str); + if ((yylval->val = flo_str_utf8(yytext)) == nil) + out_of_range_float(yyg, yytext); return NUMBER; } {FLODOT}/[^.] { - val str = string_own(utf8_dup_from(yytext)); - if (yy_top_state(yyscanner) == INITIAL || yy_top_state(yyscanner) == QSILIT || yy_top_state(yyscanner) == QWLIT) yy_pop_state(yyscanner); - if ((yylval->val = flo_str(str)) == nil) - out_of_range_float(yyg, str); + if ((yylval->val = flo_str_utf8(yytext)) == nil) + out_of_range_float(yyg, yytext); return NUMBER; } @@ -1178,9 +1174,8 @@ NJPUNC [^(){},:\[\]"~*^ \t\n] } {JNUM} { - val str = string_own(utf8_dup_from(yytext)); - if ((yylval->val = flo_str(str)) == nil) - out_of_range_float(yyg, str); + if ((yylval->val = flo_str_utf8(yytext)) == nil) + out_of_range_float(yyg, yytext); return NUMBER; } -- cgit v1.2.3