From 118254f9a6fd645556053bf31833b26d9129127b Mon Sep 17 00:00:00 2001 From: Jan Dolinar Date: Tue, 10 Oct 2023 05:58:18 +0200 Subject: [PATCH] avoid resizing empty capture and value tables --- src/packcc.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/packcc.c b/src/packcc.c index 102f163..3ce3b28 100644 --- a/src/packcc.c +++ b/src/packcc.c @@ -4716,17 +4716,19 @@ static bool_t generate(context_t *ctx) { " ctx->level++;\n", ctx->rules.buf[i]->data.rule.name ); - stream__printf( - &sstream, - " pcc_value_table__resize(ctx->auxil, &chunk->values, " FMT_LU ");\n", - (ulong_t)ctx->rules.buf[i]->data.rule.vars.len - ); - stream__printf( - &sstream, - " pcc_capture_table__resize(ctx->auxil, &chunk->capts, " FMT_LU ");\n", - (ulong_t)ctx->rules.buf[i]->data.rule.capts.len - ); + if (ctx->rules.buf[i]->data.rule.capts.len > 0) { + stream__printf( + &sstream, + " pcc_capture_table__resize(ctx->auxil, &chunk->capts, " FMT_LU ");\n", + (ulong_t)ctx->rules.buf[i]->data.rule.capts.len + ); + } if (ctx->rules.buf[i]->data.rule.vars.len > 0) { + stream__printf( + &sstream, + " pcc_value_table__resize(ctx->auxil, &chunk->values, " FMT_LU ");\n", + (ulong_t)ctx->rules.buf[i]->data.rule.vars.len + ); stream__puts( &sstream, " pcc_value_table__clear(ctx->auxil, &chunk->values);\n"