Skip to content
Permalink
Browse files

Avoid unnecessary alloc

  • Loading branch information
Eideren authored and xen2 committed Jul 18, 2019
1 parent caa44fe commit 2612f987c5408e3a845f6ba7186c61f021e58739
Showing with 15 additions and 9 deletions.
  1. +15 −9 sources/engine/Xenko.Engine/Engine/SceneInstance.cs
@@ -148,15 +148,21 @@ private void Remove(Scene scene)
scene.Entities.CollectionChanged -= Entities_CollectionChanged;
scene.Children.CollectionChanged -= Children_CollectionChanged;

var scenesToRemove = new Scene[scene.Children.Count];
scene.Children.CopyTo(scenesToRemove, 0);
foreach (var childScene in scenesToRemove)
Remove(childScene);

var entitiesToRemove = new Entity[scene.Entities.Count];
scene.Entities.CopyTo(entitiesToRemove, 0);
foreach (var entity in entitiesToRemove)
Remove(entity);
if (scene.Children.Count > 0)
{
var scenesToRemove = new Scene[scene.Children.Count];
scene.Children.CopyTo(scenesToRemove, 0);
foreach (var childScene in scenesToRemove)
Remove(childScene);
}

if (scene.Entities.Count > 0)
{
var entitiesToRemove = new Entity[scene.Entities.Count];
scene.Entities.CopyTo(entitiesToRemove, 0);
foreach (var entity in entitiesToRemove)
Remove(entity);
}
}

private void Entities_CollectionChanged(object sender, TrackingCollectionChangedEventArgs e)

0 comments on commit 2612f98

Please sign in to comment.
You can’t perform that action at this time.