when free_gamedata, also unhash all factions. speed up is_monsters().

This commit is contained in:
Enno Rehling 2014-11-07 22:58:29 +01:00
parent d1f7fb571c
commit e9084d9678
3 changed files with 8 additions and 4 deletions

View file

@ -68,6 +68,7 @@ faction *factions;
*/ */
void free_faction(faction * f) void free_faction(faction * f)
{ {
funhash(f);
if (f->msgs) if (f->msgs)
free_messagelist(f->msgs); free_messagelist(f->msgs);
while (f->battles) { while (f->battles) {
@ -113,10 +114,13 @@ void funhash(faction * f)
{ {
int index = f->no % FMAXHASH; int index = f->no % FMAXHASH;
faction **fp = factionhash + index; faction **fp = factionhash + index;
while (*fp && (*fp) != f) while (*fp && (*fp) != f) {
fp = &(*fp)->nexthash; fp = &(*fp)->nexthash;
}
if (*fp == f) {
*fp = f->nexthash; *fp = f->nexthash;
} }
}
static faction *ffindhash(int no) static faction *ffindhash(int no)
{ {

View file

@ -54,7 +54,7 @@ extern "C" {
#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT) #define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT)
#define is_monsters(f) (f && f==get_monsters()) #define is_monsters(f) (f && fval(f, FFL_NPC) && f==get_monsters())
typedef struct faction { typedef struct faction {
struct faction *next; struct faction *next;

View file

@ -733,7 +733,7 @@ void set_level(unit * u, skill_t sk, int value)
{ {
skill *sv = u->skills; skill *sv = u->skills;
assert(sk != SK_MAGIC || !u->faction || is_monsters(u->faction) || u->number == 1); assert(sk != SK_MAGIC || !u->faction || u->number == 1 || is_monsters(u->faction));
if (!skill_enabled(sk)) if (!skill_enabled(sk))
return; return;