preallocate capacity for yystack (by krishvishal)

This commit is contained in:
Jussi Saurio
2025-01-05 13:46:30 +02:00
parent fdbf62d5b3
commit d35eadb22c
2 changed files with 3 additions and 1 deletions

View File

@@ -4518,6 +4518,8 @@ void ReportTable(
print_stack_union(out,lemp,&lineno);
if( lemp->stacksize ){
fprintf(out,"const YYSTACKDEPTH: usize = %s;\n",lemp->stacksize); lineno++;
} else {
fprintf(out, "const YYSTACKDEPTH: usize = 128;\n"); lineno++;
}
if( lemp->errsym && lemp->errsym->useCnt ){
fprintf(out,"const YYERRORSYMBOL: YYCODETYPE = %d;\n",lemp->errsym->index); lineno++;

View File

@@ -285,7 +285,7 @@ impl yyParser<'_> {
yyidx: 0,
#[cfg(feature = "YYTRACKMAXSTACKDEPTH")]
yyhwm: 0,
yystack: Vec::new(),
yystack: Vec::with_capacity(YYSTACKDEPTH),
//#[cfg(not(feature = "YYNOERRORRECOVERY"))]
yyerrcnt: -1,
%% /* Optional %extra_context store */