From 024dffac8bbfa709ed3aed53d14b235e67047490 Mon Sep 17 00:00:00 2001 From: Roland Paterson-Jones Date: Wed, 16 Oct 2024 09:14:43 +0200 Subject: Blk::pred is a vector Scratching an itch - avoid unnecesary re-allocation in fillpred() which is called often in the optimisation chain. --- cfg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cfg.c b/cfg.c index 89928d5..072cd9b 100644 --- a/cfg.c +++ b/cfg.c @@ -45,10 +45,11 @@ edgedel(Blk *bs, Blk **pbd) static void addpred(Blk *bp, Blk *bc) { - if (!bc->pred) { - bc->pred = alloc(bc->npred * sizeof bc->pred[0]); - bc->visit = 0; - } + if (bc->pred) + vgrow(&bc->pred, bc->npred); + else + bc->pred = vnew(bc->npred, sizeof bc->pred[0], PFn); + assert(bc->visit < bc->npred); bc->pred[bc->visit++] = bp; } @@ -60,7 +61,7 @@ fillpreds(Fn *f) for (b=f->start; b; b=b->link) { b->npred = 0; - b->pred = 0; + b->visit = 0; } for (b=f->start; b; b=b->link) { if (b->s1) -- cgit v1.2.3