Return immediatelly if the class has been statically initialized already

This commit is contained in:
Tristan B. Kildaire 2021-06-06 21:43:42 +02:00
parent e418d98e73
commit a604f4ca27
1 changed files with 21 additions and 5 deletions

View File

@ -58,6 +58,21 @@ public void encounter(TypeChecker tc, Entity entityDependee, Entity dependentOn)
public bool hasDepChecked(TypeChecker tc, Entity entity)
{
/* Full path of the entity */
string entityFullPath = tc.getResolver().generateName(tc.getModule(), entity);
/**
* Check if it is in there
*/
foreach(string key; deps.keys)
{
import std.string : cmp;
if(cmp(key, entityFullPath) == 0)
{
return true;
}
}
return false;
}
@ -70,6 +85,10 @@ public void staticInitClass(TypeChecker tc, Clazz clazz)
/**
* Don't init if we have initted before
*/
if(hasDepChecked(tc, clazz))
{
return;
}
@ -112,11 +131,8 @@ public void staticInitClass(TypeChecker tc, Clazz clazz)
{
Clazz classType = cast(Clazz)variableType;
/* Only init if not the current class */
if(classType != clazz)
{
staticInitClass(tc, classType);
}
/* Static initialize the class */
staticInitClass(tc, classType);
}