Optimize generic GetActors/GetScripts on basic type

This commit is contained in:
Wojtek Figat
2024-09-23 21:01:04 +02:00
parent 3b3be75d94
commit 5690707c73

View File

@@ -109,6 +109,8 @@ namespace FlaxEngine
public static T[] GetScripts<T>() where T : Script
{
var scripts = GetScripts(typeof(T));
if (typeof(T) == typeof(Script))
return (T[])scripts;
if (scripts.Length == 0)
return Array.Empty<T>();
var result = new T[scripts.Length];
@@ -126,6 +128,8 @@ namespace FlaxEngine
public static T[] GetActors<T>(bool activeOnly = false) where T : Actor
{
var actors = GetActors(typeof(T), activeOnly);
if (typeof(T) == typeof(Actor))
return (T[])actors;
if (actors.Length == 0)
return Array.Empty<T>();
var result = new T[actors.Length];