--- ray/src/util/glareval.c 1991/04/03 15:20:35 1.8 +++ ray/src/util/glareval.c 1991/04/05 14:57:28 1.11 @@ -20,8 +20,8 @@ static char SCCSid[] = "$SunId$ LBL"; #define vfork fork #endif -#define MAXSBUF 409580 /* maximum total size of scanline buffer */ -#define HSIZE 227 /* size of scanline hash table */ +#define MAXSBUF 524268 /* maximum total size of scanline buffer */ +#define HSIZE 317 /* size of scanline hash table */ #define NRETIRE 16 /* number of scanlines to retire at once */ int rt_pid = -1; /* process id for rtrace */ @@ -75,6 +75,12 @@ int y; if (sl->y == y) { /* reclaim */ sl->next = hashtab[hi]; hashtab[hi] = sl; +#ifdef DEBUG + if (verbose) + fprintf(stderr, + "%s: scanline %d reclaimed\n", + progname, y); +#endif } return(sl); } @@ -410,42 +416,38 @@ SCAN * scanretire() /* retire old scanlines to free list */ { SCAN *sold[NRETIRE]; - SCAN head; int n; int h; register SCAN *sl; register int i; /* grab the NRETIRE oldest scanlines */ sold[n = 0] = NULL; - for (h = 0; h < HSIZE; h++) { - head.next = hashtab[h]; - sl = &head; - while (sl->next != NULL) { - for (i = n; i && sold[i-1]->lused > sl->next->lused; i--) - if (i == NRETIRE) { /* reallocate */ - register int oh; - oh = shash(sold[NRETIRE-1]->y); - sold[NRETIRE-1]->next = hashtab[oh]; - if (h == oh && sl == &head) - head.next = sl = sold[NRETIRE-1]; - else - hashtab[oh] = sold[NRETIRE-1]; - } else /* else bubble up */ + for (h = 0; h < HSIZE; h++) + for (sl = hashtab[h]; sl != NULL; sl = sl->next) { + for (i = n; i && sold[i-1]->lused > sl->lused; i--) + if (i < NRETIRE) sold[i] = sold[i-1]; if (i < NRETIRE) { - sold[i] = sl->next; - sl->next = sl->next->next; + sold[i] = sl; if (n < NRETIRE) /* grow list */ n++; - } else - sl = sl->next; + } } - hashtab[h] = head.next; - } /* put scanlines into free list */ - for (i = 1; i < n; i++) { - sold[i]->next = freelist; - freelist = sold[i]; + for (i = 0; i < n; i++) { + h = shash(sold[i]->y); + sl = hashtab[h]; + if (sl == sold[i]) + hashtab[h] = sl->next; + else { + while (sl->next != sold[i]) /* IS in list */ + sl = sl->next; + sl->next = sold[i]->next; + } + if (i > 0) { /* save oldest as return value */ + sold[i]->next = freelist; + freelist = sold[i]; + } } return(sold[0]); }