ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/common/calexpr.c
(Generate patch)

Comparing ray/src/common/calexpr.c (file contents):
Revision 2.52 by greg, Tue Nov 25 02:59:53 2025 UTC vs.
Revision 2.54 by greg, Sat Dec 6 02:58:05 2025 UTC

# Line 218 | Line 218 | epflatten(                     /* flatten hierarchies for '+', '*' */
218          EPNODE *epar
219   )
220   {
221 <    EPNODE      *ep;
221 >    EPNODE      *ep, *ep1;
222 >    double      combined;
223  
224 <    if (epar->nkids < 0)        /* can't handle array allocations */
224 >    if (epar->nkids <= 0)       /* can't handle array allocations */
225          return;
226  
227      for (ep = epar->v.kid; ep != NULL; ep = ep->sibling)
228 <        while (ep->type == epar->type && ep->nkids > 0) {
229 <            EPNODE      *ep1 = ep->v.kid;
228 >        while ((ep->type == epar->type) & (ep->nkids > 0)) {
229 >            ep1 = ep->v.kid;
230              while (ep1->sibling != NULL)
231                  ep1 = ep1->sibling;
232              ep1->sibling = ep->sibling;
# Line 234 | Line 235 | epflatten(                     /* flatten hierarchies for '+', '*' */
235              *ep = *ep1;
236              efree(ep1);         /* not epfree()! */
237          }
238 +    if ((epar->nkids <= 2) | !(esupport & E_RCONST))
239 +        return;
240 +    ep1 = NULL;                 /* combine constants in sum/product */
241 +    for (ep = epar->v.kid; ep != NULL; ep = ep->sibling)
242 +        if (ep->type == NUM) {
243 +            if (ep1 == NULL) combined = (ep1 = ep)->v.num;
244 +            else if (epar->type == '+') combined += ep->v.num;
245 +            else /* epar->type=='*' */ combined *= ep->v.num;
246 +        }
247 +    if (ep1 == NULL)
248 +        return;
249 +    ep1->v.num = combined;      /* drop following constants */
250 +    while (ep1->sibling != NULL)
251 +        if (ep1->sibling->type == NUM) {
252 +            ep = ep1->sibling;
253 +            ep1->sibling = ep->sibling;
254 +            efree(ep);
255 +        } else
256 +            ep1 = ep1->sibling;
257   }
258  
259  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)