perf: BehaviourController.GetBehaviours now uses Linq.Enumerable.Empty if None Found
This commit is contained in:
parent
528649659d
commit
3428fcc6ca
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue