perf: BehaviourController.GetBehaviours now uses Linq.Enumerable.Empty if None Found

This commit is contained in:
Syntriax 2024-01-24 18:40:12 +03:00
parent 528649659d
commit 3428fcc6ca
1 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Syntriax.Engine.Core.Abstract;
@ -55,17 +56,17 @@ public class BehaviourController : IBehaviourController
public IList<T> GetBehaviours<T>()
{
IList<T> behaviours = new List<T>();
List<T>? behaviours = null;
foreach (var behaviourItem in this.behaviours)
{
if (behaviourItem is not T behaviour)
continue;
behaviours ??= new List<T>();
behaviours ??= [];
behaviours.Add(behaviour);
}
return behaviours;
return behaviours ?? Enumerable.Empty<T>().ToList();
}
public void RemoveBehaviour<T>(bool removeAll = false) where T : class, IBehaviour