From: divverent Date: Tue, 15 Jul 2008 08:19:43 +0000 (+0000) Subject: small optimization to the leak check, to mark the entities faster X-Git-Tag: xonotic-v0.1.0preview~2176 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=adaa65210c2b4c8a67af94ffc30bcb9aa499e283 small optimization to the leak check, to mark the entities faster git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8404 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/progs.h b/progs.h index d5e59dbf..51e1c9da 100644 --- a/progs.h +++ b/progs.h @@ -33,7 +33,7 @@ typedef struct edict_engineprivate_s // mess up client interpolation or obscure severe QuakeC bugs) float freetime; // mark for the leak detector - qboolean marked; + int mark; // place in the code where it was allocated (for the leak detector) const char *allocation_origin; // initially false to prevent projectiles from moving on their first frame diff --git a/progsvm.h b/progsvm.h index ce900af7..8386e996 100644 --- a/progsvm.h +++ b/progsvm.h @@ -67,7 +67,7 @@ typedef struct prvm_edict_private_s { qboolean free; float freetime; - qboolean marked; + int mark; const char *allocation_origin; } prvm_edict_private_t; diff --git a/prvm_edict.c b/prvm_edict.c index 204fb3bd..96c3557f 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -2501,7 +2501,7 @@ static qboolean PRVM_IsEdictRelevant(prvm_edict_t *edict) return false; } -static qboolean PRVM_IsEdictReferenced(prvm_edict_t *edict) +static qboolean PRVM_IsEdictReferenced(prvm_edict_t *edict, int mark) { int i, j; int edictnum = PRVM_NUM_FOR_EDICT(edict); @@ -2530,7 +2530,7 @@ static qboolean PRVM_IsEdictReferenced(prvm_edict_t *edict) for(j = 0; j < prog->num_edicts; ++j) { prvm_edict_t *ed = PRVM_EDICT_NUM(j); - if (!ed->priv.required->marked) + if (ed->priv.required->mark < mark) continue; if(ed == edict) continue; @@ -2558,15 +2558,17 @@ static void PRVM_MarkReferencedEdicts() { int j; qboolean found_new; + int stage; for(j = 0; j < prog->num_edicts; ++j) { prvm_edict_t *ed = PRVM_EDICT_NUM(j); if(ed->priv.required->free) continue; - ed->priv.required->marked = PRVM_IsEdictRelevant(ed); + ed->priv.required->mark = PRVM_IsEdictRelevant(ed) ? 1 : 0; } + stage = 1; do { found_new = false; @@ -2575,16 +2577,18 @@ static void PRVM_MarkReferencedEdicts() prvm_edict_t *ed = PRVM_EDICT_NUM(j); if(ed->priv.required->free) continue; - if(ed->priv.required->marked) + if(ed->priv.required->mark) continue; - if(PRVM_IsEdictReferenced(ed)) + if(PRVM_IsEdictReferenced(ed, stage)) { - ed->priv.required->marked = true; + ed->priv.required->mark = stage + 1; found_new = true; } } + ++stage; } while(found_new); + Con_DPrintf("leak check used %d stages to find all references\n", stage); } void PRVM_LeakTest() @@ -2615,7 +2619,7 @@ void PRVM_LeakTest() prvm_edict_t *ed = PRVM_EDICT_NUM(j); if(ed->priv.required->free) continue; - if(!ed->priv.required->marked) + if(!ed->priv.required->mark) if(ed->priv.required->allocation_origin) { Con_Printf("Unreferenced edict found!\n Allocated at: %s\n", ed->priv.required->allocation_origin);