prepare_report/add_seen vielfach schneller gemacht.

This commit is contained in:
Enno Rehling 2002-05-05 08:46:27 +00:00
parent a5ccf84555
commit 3a9a58a391
1 changed files with 30 additions and 15 deletions

View File

@ -2548,12 +2548,13 @@ find_seen(const region * r)
return NULL; return NULL;
} }
seen_region * last;
static boolean static boolean
add_seen(const struct region * r, unsigned char mode, boolean dis) add_seen(const struct region * r, unsigned char mode, boolean dis)
{ {
seen_region * find = find_seen(r); seen_region * find = find_seen(r);
if (find==NULL) { if (find==NULL) {
seen_region * insert; seen_region * insert = NULL;
int index = abs((r->x & 0xffff) + ((r->y) << 16)) % MAXSEEHASH; int index = abs((r->x & 0xffff) + ((r->y) << 16)) % MAXSEEHASH;
if (!reuse) reuse = (seen_region*)calloc(1, sizeof(struct seen_region)); if (!reuse) reuse = (seen_region*)calloc(1, sizeof(struct seen_region));
find = reuse; find = reuse;
@ -2562,26 +2563,40 @@ add_seen(const struct region * r, unsigned char mode, boolean dis)
seehash[index] = find; seehash[index] = find;
find->r = r; find->r = r;
for (insert=last;insert;insert=insert->next) { /* first attempt: try to put it between previous insertion point and
const region * rl; * last region known so far. It's quite likely to be here. */
if (last) {
for (insert=last;insert->next;insert=insert->next) {
region * rl;
seen_region * inext = insert->next; seen_region * inext = insert->next;
for (rl=insert->r;rl && (!inext || rl!=inext->r);rl=rl->next) { for (rl=insert->r->next;rl && rl!=inext->r;rl=rl->next) {
if (rl==r) break; if (rl==r) break;
} }
if (rl==r) break; if (rl==r) break;
} }
if (insert==0) { /* if we did not find it, and mode is not see_neighbour, it *still*
for (insert=seen;insert!=last;insert=insert->next) { * belongs at the end. otherwise, search more: */
const region * rl; if (insert->next==NULL && mode==see_neighbour) {
seen_region * inext = insert->next; const region * rl = NULL;
for (rl=insert->r;rl && (!inext || rl!=inext->r);rl=rl->next) { seen_region * sprev;
for(sprev=seen;sprev!=last;sprev=sprev->next) {
seen_region * snext = sprev->next;
for (rl=sprev->r->next;rl!=snext->r;rl=rl->next) {
if (rl==r) break; if (rl==r) break;
} }
if (rl==r) break; if (rl==r) break;
} }
if (insert==last) insert=0; /* search it after the insertion point, all the way to the end */
if (rl==r) insert = sprev;
else {
for (rl=insert->r->next;rl;rl=rl->next) {
if (rl==r) break;
} }
last = find; if (rl!=r) insert=NULL; /* in front */
}
}
}
if (mode!=see_neighbour) last=find;
find->prev = insert; find->prev = insert;
if (insert!=0) { if (insert!=0) {
find->next = insert->next; find->next = insert->next;