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

Comparing ray/src/common/modobject.c (file contents):
Revision 2.24 by greg, Sat Jun 21 00:15:30 2025 UTC vs.
Revision 2.25 by greg, Sat Jun 21 17:42:17 2025 UTC

# Line 10 | Line 10 | static const char RCSid[] = "$Id$";
10   #include "copyright.h"
11  
12   #include  "standard.h"
13
13   #include  "object.h"
15
14   #include  "otypes.h"
15  
16  
# Line 29 | Line 27 | objndx(                                /* get object number from pointer */
27          OBJREC  *op
28   )
29   {
30 <        int     i;
31 <
30 > #ifndef ONCACHESIZ
31 > #define ONCACHESIZ      907     /* keep a cache of previous searches */
32 > #endif
33 >        static OBJECT   oncache[ONCACHESIZ];
34 >        const int       ent = (size_t)op % ONCACHESIZ;
35 >        int             i;
36 >                                /* clear cache on first call */
37 >        for (i = ONCACHESIZ*(!oncache[0] & !oncache[1]); i--; )
38 >                oncache[i] = OVOID;
39 >                                /* is this pointer in cache? */
40 >        if ((oncache[ent] != OVOID) & (oncache[ent] < nobjects) &&
41 >                                objptr(oncache[ent]) == op)
42 >                return(oncache[ent]);           /* matches previous search */
43 >                                /* else look for allocated block */
44          for (i = (nobjects-1)>>OBJBLKSHFT; i >= 0; i--)
45 <                if ((objblock[i] <= op) & (op < objblock[i]+OBJBLKSIZ))
46 <                        return( ((OBJECT)i << OBJBLKSHFT) +
47 <                                        (OBJECT)(op - objblock[i]) );
48 <
45 >                if ((objblock[i] <= op) & (op < objblock[i]+OBJBLKSIZ)) {
46 >                                /* found it -- save index to cache */
47 >                        oncache[ent] = ((OBJECT)i << OBJBLKSHFT) +
48 >                                                (op - objblock[i]);
49 >                        return(oncache[ent]);
50 >                }
51          return(OVOID);          /* not in our array -- may still be valid */
52   }
53  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines