[hackers] [scc] Reduce the number of decay() calls || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 14 Aug 2015 17:08:59 +0200 (CEST)

commit 411c5618c377b28556835dcb7ad756b6072644e4
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Fri Aug 14 14:44:25 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Fri Aug 14 14:44:25 2015 +0200

    Reduce the number of decay() calls
    
    Decay() is called from eval, so it is not needed anymore
    all these calls to decay() around the code.

diff --git a/cc1/expr.c b/cc1/expr.c
index e76d8ac..f6530f5 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -267,9 +267,16 @@ chklvalue(Node *np, Type *tp)
                 error("invalid use of void expression");
 }
 
-/* TODO: put decay() call in a better place, because at this
- moment we call dozens of calls in all the code */
-static Node *decay(Node *np);
+static Node *
+decay(Node *np)
+{
+ Type *tp = np->type;
+
+ if (tp->op == ARY)
+ tp = tp->type;
+
+ return node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL);
+}
 
 Node *
 eval(Node *np)
_AT_@ -326,17 +333,6 @@ integeruop(char op, Node *np)
 }
 
 static Node *
-decay(Node *np)
-{
- Type *tp = np->type;
-
- if (tp->op == ARY)
- tp = tp->type;
-
- return node(OADDR, mktype(tp, PTR, 0, NULL), np, NULL);
-}
-
-static Node *
 constconv(Node *np, Type *newtp)
 {
         Type *oldtp = np->type;
_AT_@ -449,8 +445,6 @@ parithmetic(char op, Node *lp, Node *rp)
 
         tp = lp->type;
         size = sizeofnode(tp->type);
- if (BTYPE(rp) == ARY)
- rp = decay(rp);
 
         if (op == OSUB && BTYPE(rp) == PTR) {
                 if (tp != rp->type)
_AT_@ -481,8 +475,6 @@ arithmetic(char op, Node *lp, Node *rp)
                 case FLOAT:
                         typeconv(&lp, &rp);
                         break;
- case ARY:
- rp = decay(rp);
                 case PTR:
                         if (op == OADD || op == OSUB)
                                 return parithmetic(op, rp, lp);
_AT_@ -490,8 +482,6 @@ arithmetic(char op, Node *lp, Node *rp)
                         goto incorrect;
                 }
                 break;
- case ARY:
- lp = decay(lp);
         case PTR:
                 return parithmetic(op, lp, rp);
         default:
_AT_@ -534,18 +524,12 @@ compare(char op, Node *lp, Node *rp)
                 case FLOAT:
                         typeconv(&lp, &rp);
                         break;
- case ARY:
- case FTN:
- rp = decay(rp);
                 case PTR:
                         return pcompare(op, rp, lp);
                 default:
                         goto nocompat;
                 }
                 break;
- case ARY:
- case FTN:
- lp = decay(lp);
         case PTR:
                 return pcompare(op, lp, rp);
         default:
_AT_@ -642,15 +626,12 @@ iszero(Node *np)
 static Node *
 assignop(char op, Node *lp, Node *rp)
 {
- switch (BTYPE(rp)) {
- case FTN:
- case ARY:
- rp = decay(rp);
- /* PASSTHROUGH */
- default:
- if ((rp = convert(rp, lp->type, 0)) == NULL)
- error("incompatible types when assigning");
- }
+ lp = eval(lp);
+ rp = eval(rp);
+
+ if ((rp = convert(rp, lp->type, 0)) == NULL)
+ error("incompatible types when assigning");
+
         return node(op, lp->type, lp, rp);
 }
 
_AT_@ -692,7 +673,8 @@ static Node *
 content(char op, Node *np)
 {
         switch (BTYPE(np)) {
- case ARY: case FTN:
+ case ARY:
+ case FTN:
                 np = decay(np);
         case PTR:
                 np = node(op, np->type->type, np, NULL);
_AT_@ -1133,7 +1115,7 @@ assign(void)
                 }
                 chklvalue(np, np->type);
                 next();
- np = (fun)(op, np, eval(assign()));
+ np = (fun)(op, np, assign());
         }
 }
 
Received on Fri Aug 14 2015 - 17:08:59 CEST

This archive was generated by hypermail 2.3.0 : Fri Aug 14 2015 - 17:12:15 CEST