ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/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.26 by greg, Sun Jun 22 17:21:37 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;
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;  /* hash on pointer */
35 >        int             i, lastblock;
36  
37 <        for (i = (nobjects-1)>>OBJBLKSHFT; i >= 0; i--)
38 <                if ((objblock[i] <= op) & (op < objblock[i]+OBJBLKSIZ))
39 <                        return( ((OBJECT)i << OBJBLKSHFT) +
40 <                                        (OBJECT)(op - objblock[i]) );
41 <
42 <        return(OVOID);          /* not in our array -- may still be valid */
37 > #if OVOID != 0                  /* clear cache on first call */
38 >        for (i = ONCACHESIZ*(!oncache[0] & !oncache[1]); i--; )
39 >                oncache[i] = OVOID;
40 > #endif
41 >                                /* is this pointer in cache? */
42 >        if ((oncache[ent] != OVOID) & (oncache[ent] < nobjects) &&
43 >                                objptr(oncache[ent]) == op)
44 >                return(oncache[ent]);           /* matches previous search */
45 >                                /* else search for our block from first */
46 >        lastblock = (nobjects-1)>>OBJBLKSHFT;
47 >        for (i = 0; i <= lastblock; i++)
48 >                if ((objblock[i] <= op) & (op < objblock[i]+OBJBLKSIZ)) {
49 >                                /* found it -- cache corresponding index */
50 >                        oncache[ent] = ((OBJECT)i << OBJBLKSHFT) +
51 >                                                (op - objblock[i]);
52 >                        return(oncache[ent]);
53 >                }
54 >        return(OVOID);          /* not allocated -- may still be valid */
55   }
56  
57  

Diff Legend

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