Skip to content

Commit

Permalink
More foreach removal
Browse files Browse the repository at this point in the history
Added instruction clearing on pooled entities.
Added memory output in release mode.
  • Loading branch information
vchelaru committed Dec 27, 2023
1 parent 9cb6826 commit f3027db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 3 additions & 6 deletions Engines/FlatRedBallXNA/FlatRedBall/Debugging/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ public enum Corner

static List<string> mCommandLineOutput = new List<string>();

#if DEBUG
// Why is this expensive to have in debug? If the user doesn't ask for memory, this doesn't get used.
//#if DEBUG
static RollingAverage mAllocationAverage = new RollingAverage(4);
static long mLastMemoryUse = -1;
#endif
//#endif

public static StringBuilder LogStringBuilder = new StringBuilder();

Expand Down Expand Up @@ -212,7 +213,6 @@ public static string ForceGetMemoryInformation()
currentUsage = GC.GetTotalMemory(false);
memoryInformation = "Total Memory: " + currentUsage.ToString("N0");

#if DEBUG
if (mLastMemoryUse >= 0)
{
long difference = currentUsage - mLastMemoryUse;
Expand All @@ -224,12 +224,9 @@ public static string ForceGetMemoryInformation()
}
memoryInformation += "\nAverage Growth per second: " +
mAllocationAverage.Average.ToString("N0");
#endif

LastCalculationTime = TimeManager.CurrentTime;
#if DEBUG
mLastMemoryUse = currentUsage;
#endif


return memoryInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public override ICodeBlock GenerateDestroy(ICodeBlock codeBlock, IElement elemen

}
}
else if(element is EntitySave entitySave && entitySave.PooledByFactory && entitySave.CreatedByOtherEntities)
{
codeBlock.Line($"this.Instructions.Clear();");
}

return codeBlock;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,9 +1157,10 @@ private void TryPushBindingContextChangeToChildren(string vmPropertyName)
{
if (this.Children != null)
{
foreach(var child in Children)
for (int i = 0; i < Children.Count; i++)
{
if(child is GraphicalUiElement gue)
IRenderableIpso child = Children[i];
if (child is GraphicalUiElement gue)
{
if (gue.BindingContextBinding == vmPropertyName && gue.BindingContextBindingPropertyOwner == EffectiveBindingContext)
{
Expand All @@ -1171,8 +1172,9 @@ private void TryPushBindingContextChangeToChildren(string vmPropertyName)
}
else
{
foreach(var gue in ContainedElements)
for (int i = 0; i < mWhatThisContains.Count; i++)
{
GraphicalUiElement gue = mWhatThisContains[i];
if (gue.BindingContextBinding == vmPropertyName && gue.BindingContextBindingPropertyOwner == EffectiveBindingContext)
{
gue.UpdateToVmProperty(vmPropertyName);
Expand Down

0 comments on commit f3027db

Please sign in to comment.