From 1d1912971e771773fa8041bddd100065bfb752be Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Mon, 17 Jul 2023 22:33:03 -0400 Subject: [PATCH] libcdecl: Avoid redundant string literal in yyerror. The T_LEX_ERROR string literal in yyerror won't be merged with the now-duplicate string in the token name table; use the appropriate indirection to shave off some bytes. --- src/parse.y | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/parse.y b/src/parse.y index b77cfbb..abfccd2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -76,6 +76,7 @@ const char *cdecl__token_name(unsigned token); } %{ +static void yyerror(YYLTYPE *, yyscan_t, struct cdecl **, const char *); static void free_decl(struct cdecl *); static void free_declspec(struct cdecl_declspec *x) @@ -141,15 +142,6 @@ void cdecl__free(struct cdecl *decl) { free_decl(decl); } - -static void -yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) -{ - if (strstr(err, "T_LEX_ERROR")) - return; - - cdecl__err(CDECL_ENOPARSE, "%s", err); -} %} %destructor { free($$); } @@ -614,3 +606,12 @@ const char *cdecl__token_name(unsigned token) { return yytname[YYTRANSLATE(token)]; } + +static void +yyerror(YYLTYPE *loc, yyscan_t scanner, struct cdecl **out, const char *err) +{ + if (strstr(err, yytname[YYTRANSLATE(T_LEX_ERROR)])) + return; + + cdecl__err(CDECL_ENOPARSE, "%s", err); +} -- 2.43.2