Beschleunigung des von get_seen_interval (Dank ENUM_REGIONS)

This commit is contained in:
Enno Rehling 2005-05-01 00:26:15 +00:00
parent b445cc1ed3
commit f8ef91907a
4 changed files with 61 additions and 42 deletions

View file

@ -1073,27 +1073,6 @@ cr_borders(seen_region ** seen, const region * r, const faction * f, int seemode
}
}
void
get_seen_interval(struct seen_region ** seen, region ** first, region ** last)
{
/* #ifdef ENUM_REGIONS : can speed stuff up */
region * r = regions;
while (r!=NULL) {
if (find_seen(seen, r)!=NULL) {
*first = r;
break;
}
r = r->next;
}
while (r!=NULL) {
if (find_seen(seen, r)!=NULL) {
*last = r->next;
}
r = r->next;
}
}
/* main function of the creport. creates the header and traverses all regions */
int
report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction_list * addresses,
@ -1108,11 +1087,11 @@ report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction
unit *u;
int score = 0, avgscore = 0;
const char * mailto = locale_string(f->locale, "mailto");
region * first = NULL, * last = NULL;
region * first = firstregion(f), * last = lastregion(f);
const attrib * a;
/* must call this to get all the neighbour regions */
get_seen_interval(seen, &first, &last);
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
/* initialisations, header and lists */

View file

@ -966,8 +966,46 @@ find_seen(struct seen_region * seehash[], const region * r)
return NULL;
}
void
get_seen_interval(struct seen_region ** seen, region ** first, region ** last)
{
/* this is required to find the neighbour regions of the ones we are in,
* which may well be outside of [firstregion, lastregion) */
#ifdef ENUM_REGIONS
int i;
for (i=0;i!=MAXSEEHASH;++i) {
seen_region * sr = seen[i];
while (sr!=NULL) {
if (*first==NULL || sr->r->index<(*first)->index) {
*first = sr->r;
}
if (*last!=NULL && sr->r->index>=(*last)->index) {
*last = sr->r->next;
}
sr = sr->nextHash;
}
}
#else
region * r = regions;
while (r!=first) {
if (find_seen(seen, r)!=NULL) {
*first = r;
break;
}
r = r->next;
}
r = *last;
while (r!=NULL) {
if (find_seen(seen, r)!=NULL) {
*last = r->next;
}
r = r->next;
}
#endif
}
boolean
add_seen(struct seen_region * seehash[], const struct region * r, unsigned char mode, boolean dis)
add_seen(struct seen_region * seehash[], struct region * r, unsigned char mode, boolean dis)
{
seen_region * find = find_seen(seehash, r);
if (find==NULL) {

View file

@ -75,16 +75,17 @@ enum {
typedef struct seen_region {
struct seen_region * nextHash;
const struct region *r;
struct region *r;
unsigned char mode;
boolean disbelieves;
} seen_region;
extern struct seen_region * find_seen(struct seen_region * seehash[], const struct region * r);
extern boolean add_seen(struct seen_region * seehash[], const struct region * r, unsigned char mode, boolean dis);
extern boolean add_seen(struct seen_region * seehash[], struct region * r, unsigned char mode, boolean dis);
extern struct seen_region ** seen_init(void);
extern void seen_done(struct seen_region * seehash[]);
extern void free_seen(void);
extern void get_seen_interval(struct seen_region ** seen, struct region ** first, struct region ** last);
extern const char* resname(resource_t res, int i);

View file

@ -164,6 +164,7 @@ report_segfault(int signo, siginfo_t * sinf, void * arg)
size_t size;
int fd = fileno(stderr);
fflush(stdout);
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
size = backtrace(btrace, 50);
backtrace_symbols_fd(btrace, size, fd);