From 3428fcc6ca759805c26f742f9b2ca820953c3ba3 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Wed, 24 Jan 2024 18:40:12 +0300 Subject: [PATCH] perf: BehaviourController.GetBehaviours now uses Linq.Enumerable.Empty if None Found --- Engine.Core/BehaviourController.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Engine.Core/BehaviourController.cs b/Engine.Core/BehaviourController.cs index 98d4585..582276b 100644 --- a/Engine.Core/BehaviourController.cs +++ b/Engine.Core/BehaviourController.cs @@ -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 GetBehaviours() { - IList behaviours = new List(); + List? behaviours = null; foreach (var behaviourItem in this.behaviours) { if (behaviourItem is not T behaviour) continue; - behaviours ??= new List(); + behaviours ??= []; behaviours.Add(behaviour); } - return behaviours; + return behaviours ?? Enumerable.Empty().ToList(); } public void RemoveBehaviour(bool removeAll = false) where T : class, IBehaviour