forked from github/server
Beschleunigung des von get_seen_interval (Dank ENUM_REGIONS)
This commit is contained in:
parent
b445cc1ed3
commit
f8ef91907a
4 changed files with 61 additions and 42 deletions
|
@ -1073,48 +1073,27 @@ 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 */
|
/* main function of the creport. creates the header and traverses all regions */
|
||||||
int
|
int
|
||||||
report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction_list * addresses,
|
report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction_list * addresses,
|
||||||
const time_t report_time)
|
const time_t report_time)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
item * itm;
|
item * itm;
|
||||||
const char * prefix;
|
const char * prefix;
|
||||||
region * r;
|
region * r;
|
||||||
building *b;
|
building *b;
|
||||||
ship *sh;
|
ship *sh;
|
||||||
unit *u;
|
unit *u;
|
||||||
int score = 0, avgscore = 0;
|
int score = 0, avgscore = 0;
|
||||||
const char * mailto = locale_string(f->locale, "mailto");
|
const char * mailto = locale_string(f->locale, "mailto");
|
||||||
region * first = NULL, * last = NULL;
|
region * first = firstregion(f), * last = lastregion(f);
|
||||||
const attrib * a;
|
const attrib * a;
|
||||||
|
|
||||||
|
/* must call this to get all the neighbour regions */
|
||||||
get_seen_interval(seen, &first, &last);
|
get_seen_interval(seen, &first, &last);
|
||||||
|
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
||||||
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
|
/* initialisations, header and lists */
|
||||||
/* initialisations, header and lists */
|
|
||||||
|
|
||||||
fprintf(F, "VERSION %d\n", C_REPORT_VERSION);
|
fprintf(F, "VERSION %d\n", C_REPORT_VERSION);
|
||||||
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
|
fprintf(F, "\"%s\";locale\n", locale_name(f->locale));
|
||||||
|
@ -1255,12 +1234,12 @@ report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* traverse all regions */
|
/* traverse all regions */
|
||||||
for (r=first;r!=last;r=r->next) {
|
for (r=first;r!=last;r=r->next) {
|
||||||
int modifier = 0;
|
int modifier = 0;
|
||||||
const char * tname;
|
const char * tname;
|
||||||
const seen_region * sd = find_seen(seen, r);
|
const seen_region * sd = find_seen(seen, r);
|
||||||
|
|
||||||
if (sd==NULL) continue;
|
if (sd==NULL) continue;
|
||||||
|
|
||||||
if (!rplane(r)) {
|
if (!rplane(r)) {
|
||||||
|
|
|
@ -966,8 +966,46 @@ find_seen(struct seen_region * seehash[], const region * r)
|
||||||
return NULL;
|
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
|
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);
|
seen_region * find = find_seen(seehash, r);
|
||||||
if (find==NULL) {
|
if (find==NULL) {
|
||||||
|
|
|
@ -74,17 +74,18 @@ enum {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct seen_region {
|
typedef struct seen_region {
|
||||||
struct seen_region * nextHash;
|
struct seen_region * nextHash;
|
||||||
const struct region *r;
|
struct region *r;
|
||||||
unsigned char mode;
|
unsigned char mode;
|
||||||
boolean disbelieves;
|
boolean disbelieves;
|
||||||
} seen_region;
|
} seen_region;
|
||||||
|
|
||||||
extern struct seen_region * find_seen(struct seen_region * seehash[], const struct region * r);
|
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 struct seen_region ** seen_init(void);
|
||||||
extern void seen_done(struct seen_region * seehash[]);
|
extern void seen_done(struct seen_region * seehash[]);
|
||||||
extern void free_seen(void);
|
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);
|
extern const char* resname(resource_t res, int i);
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,7 @@ report_segfault(int signo, siginfo_t * sinf, void * arg)
|
||||||
size_t size;
|
size_t size;
|
||||||
int fd = fileno(stderr);
|
int fd = fileno(stderr);
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
|
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
|
||||||
size = backtrace(btrace, 50);
|
size = backtrace(btrace, 50);
|
||||||
backtrace_symbols_fd(btrace, size, fd);
|
backtrace_symbols_fd(btrace, size, fd);
|
||||||
|
|
Loading…
Reference in a new issue