From: Nick Bowler Date: Sun, 19 Nov 2023 01:05:23 +0000 (-0500) Subject: libcdecl: Prefer memchr over strchr in the scanner. X-Git-Tag: v1.3~82 X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/commitdiff_plain/82cedba63a97c4afde1440751585759888384883 libcdecl: Prefer memchr over strchr in the scanner. Since nothing else in the library uses strchr, but we do use memchr elsewhere, using memchr instead avoids a comparatively expensive PLT entry. We already know the string length so the only real difference is the additional argument marshalling. --- diff --git a/src/scan.l b/src/scan.l index 7549e6f..2b92846 100644 --- a/src/scan.l +++ b/src/scan.l @@ -157,9 +157,10 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ } {IDENT} { - unsigned x = cdecl__to_keyword(yytext, yyleng, yyextra); - int tok; + int len = yyleng, tok; + unsigned x; + x = cdecl__to_keyword(yytext, len, yyextra); yylval->spectype = UNPACK_SPEC(x & 0xff); if ((tok = (x >> 8)) == PACK_TOKEN(T_IDENT)) { /* @@ -173,14 +174,14 @@ INTEGER 0x[[:xdigit:]]+|0[0-7]+|[[:digit:]]+ * downsides. */ #if 1 - if ((c = strchr(yytext, '-'))) + if ((c = memchr(yytext, '-', len))) goto invalid_char; #else yyless(strcspn(yytext, "-")); #endif - if (!(yylval->item = cdecl__alloc_item(yyleng+1))) + if (!(yylval->item = cdecl__alloc_item(len+1))) return T_LEX_ERROR; \ - memcpy(yylval->item->s, yytext, yyleng+1); + memcpy(yylval->item->s, yytext, len+1); } return UNPACK_TOKEN(tok); }