--- ray/src/common/modobject.c 2025/06/21 17:42:17 2.25 +++ ray/src/common/modobject.c 2025/06/22 17:21:37 2.26 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: modobject.c,v 2.25 2025/06/21 17:42:17 greg Exp $"; +static const char RCSid[] = "$Id: modobject.c,v 2.26 2025/06/22 17:21:37 greg Exp $"; #endif /* * Routines for tracking object modifiers @@ -31,24 +31,27 @@ objndx( /* get object number from pointer */ #define ONCACHESIZ 907 /* keep a cache of previous searches */ #endif static OBJECT oncache[ONCACHESIZ]; - const int ent = (size_t)op % ONCACHESIZ; - int i; - /* clear cache on first call */ + const int ent = (size_t)op % ONCACHESIZ; /* hash on pointer */ + int i, lastblock; + +#if OVOID != 0 /* clear cache on first call */ for (i = ONCACHESIZ*(!oncache[0] & !oncache[1]); i--; ) oncache[i] = OVOID; +#endif /* is this pointer in cache? */ if ((oncache[ent] != OVOID) & (oncache[ent] < nobjects) && objptr(oncache[ent]) == op) return(oncache[ent]); /* matches previous search */ - /* else look for allocated block */ - for (i = (nobjects-1)>>OBJBLKSHFT; i >= 0; i--) + /* else search for our block from first */ + lastblock = (nobjects-1)>>OBJBLKSHFT; + for (i = 0; i <= lastblock; i++) if ((objblock[i] <= op) & (op < objblock[i]+OBJBLKSIZ)) { - /* found it -- save index to cache */ + /* found it -- cache corresponding index */ oncache[ent] = ((OBJECT)i << OBJBLKSHFT) + (op - objblock[i]); return(oncache[ent]); } - return(OVOID); /* not in our array -- may still be valid */ + return(OVOID); /* not allocated -- may still be valid */ }