commit d603b01749058d99f191934ebbefb0f8a56328eb
parent 8433368cb88bceb2510fadea9ad5ccbae33c6f3a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 31 Dec 2024 16:44:41 +0100
cc2: Use precalculated information in swtch()
We already have all the required information in the Swtch struct,
so we can reuse it instead of calculating it again.
Diffstat:
1 file changed, 7 insertions(+), 16 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/swtch.c b/src/cmd/scc-cc/cc2/swtch.c
@@ -87,27 +87,18 @@ swtch_dir(Node *np, int n, TINT min, TINT max)
Node *
swtch(Node *np)
{
+ Swtch *swt;
int n;
- TINT min, max, range, val;
- Node *p, *def = NULL;
+ TINT min, max, range;
- min = TINT_MAX;
- max = n = 0;
- for (p = np->next; p->op != OESWITCH; p = p->next) {
- if (p->op != ODEFAULT) {
- val = p->left->u.i;
- if (val > max)
- max = val;
- if (val < min)
- min = val;
- ++n;
- }
- }
+ swt = np->u.swtch;
+ min = swt->min;
+ max = swt->max;
+ range = max - min + 1;
+ n = swt->nr;
if (n < 4)
return swtch_if(np);
-
- range = max - min + 1;
if (range == n)
return swtch_dir(np, range, min, max);