| 10 |
|
#include "copyright.h" |
| 11 |
|
|
| 12 |
|
#include "standard.h" |
| 13 |
– |
|
| 13 |
|
#include "object.h" |
| 15 |
– |
|
| 14 |
|
#include "otypes.h" |
| 15 |
|
|
| 16 |
|
|
| 17 |
|
static struct ohtab { |
| 18 |
< |
int hsiz; /* current table size */ |
| 19 |
< |
OBJECT *htab; /* table, if allocated */ |
| 18 |
> |
int hsiz; /* current table size */ |
| 19 |
> |
OBJECT *htab; /* table, if allocated */ |
| 20 |
|
} modtab = {100, NULL}, objtab = {1000, NULL}; /* modifiers and objects */ |
| 21 |
|
|
| 22 |
|
static int otndx(char *, struct ohtab *); |
| 27 |
|
OBJREC *op |
| 28 |
|
) |
| 29 |
|
{ |
| 30 |
< |
int i, j; |
| 31 |
< |
|
| 32 |
< |
for (i = nobjects>>OBJBLKSHFT; i >= 0; i--) { |
| 33 |
< |
j = op - objblock[i]; |
| 34 |
< |
if ((j >= 0) & (j < OBJBLKSIZ)) |
| 35 |
< |
return((i<<OBJBLKSHFT) + j); |
| 36 |
< |
} |
| 37 |
< |
return(OVOID); |
| 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 |
> |
/* 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 |
|
|
| 54 |
|
|
| 59 |
|
) |
| 60 |
|
{ |
| 61 |
|
OBJREC *op; |
| 62 |
< |
int i; |
| 62 |
> |
OBJECT i; |
| 63 |
|
|
| 64 |
|
i = modifier(mname); /* try hash table first */ |
| 65 |
|
if ((obj == OVOID) | (i < obj)) |
| 66 |
|
return(i); |
| 67 |
|
for (i = obj; i-- > 0; ) { /* need to search */ |
| 68 |
|
op = objptr(i); |
| 69 |
< |
if (ismodifier(op->otype) && op->oname[0] == mname[0] && |
| 70 |
< |
!strcmp(op->oname, mname)) |
| 69 |
> |
if ((ismodifier(op->otype) != 0) & (op->oname[0] == mname[0]) |
| 70 |
> |
&& !strcmp(op->oname, mname)) |
| 71 |
|
return(i); |
| 72 |
|
} |
| 73 |
|
return(OVOID); |
| 207 |
|
|
| 208 |
|
if (nobjects <= 0) { |
| 209 |
|
if (modtab.htab != NULL) { |
| 210 |
< |
free((void *)modtab.htab); |
| 210 |
> |
free(modtab.htab); |
| 211 |
|
modtab.htab = NULL; |
| 212 |
|
modtab.hsiz = 100; |
| 213 |
|
} |
| 214 |
|
if (objtab.htab != NULL) { |
| 215 |
< |
free((void *)objtab.htab); |
| 215 |
> |
free(objtab.htab); |
| 216 |
|
objtab.htab = NULL; |
| 217 |
|
objtab.hsiz = 100; |
| 218 |
|
} |
| 234 |
|
) |
| 235 |
|
{ |
| 236 |
|
static int hsiztab[] = { |
| 237 |
< |
251, 509, 1021, 2039, 4093, 8191, 16381, 0 |
| 237 |
> |
251, 509, 1021, 2039, 4093, 8191, 16381, |
| 238 |
> |
32749, 65521, 131071, 262139, 0 |
| 239 |
|
}; |
| 240 |
|
int *hsp; |
| 241 |
|
|
| 252 |
|
struct ohtab *tab |
| 253 |
|
) |
| 254 |
|
{ |
| 255 |
+ |
char *onm; |
| 256 |
|
OBJECT *oldhtab; |
| 257 |
|
int hval, i; |
| 258 |
|
int ndx; |
| 271 |
|
tryagain: |
| 272 |
|
for (i = 0; i < tab->hsiz; i++) { |
| 273 |
|
ndx = (hval + (unsigned long)i*i) % tab->hsiz; |
| 274 |
< |
if (tab->htab[ndx] == OVOID || |
| 261 |
< |
!strcmp(objptr(tab->htab[ndx])->oname, name)) |
| 274 |
> |
if (tab->htab[ndx] == OVOID) |
| 275 |
|
return(ndx); |
| 276 |
+ |
onm = objptr(tab->htab[ndx])->oname; |
| 277 |
+ |
if (onm != NULL && !strcmp(onm, name)) |
| 278 |
+ |
return(ndx); |
| 279 |
|
} |
| 280 |
|
/* table is full, reallocate */ |
| 281 |
|
oldhtab = tab->htab; |
| 283 |
|
tab->htab = NULL; |
| 284 |
|
while (ndx--) |
| 285 |
|
if (oldhtab[ndx] != OVOID) { |
| 286 |
< |
i = otndx(objptr(oldhtab[ndx])->oname, tab); |
| 286 |
> |
onm = objptr(oldhtab[ndx])->oname; |
| 287 |
> |
if (onm == NULL) |
| 288 |
> |
continue; |
| 289 |
> |
i = otndx(onm, tab); |
| 290 |
|
tab->htab[i] = oldhtab[ndx]; |
| 291 |
|
} |
| 292 |
< |
free((void *)oldhtab); |
| 292 |
> |
free(oldhtab); |
| 293 |
|
goto tryagain; /* should happen only once! */ |
| 294 |
|
} |