From d7b40e33b1fc6fba18813267e57c48441892b756 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 14 Feb 2024 21:20:00 +0800 Subject: [PATCH] optimize CreatePool --- src/EcsWorld.pools.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/EcsWorld.pools.cs b/src/EcsWorld.pools.cs index 22522f0..8f8f74f 100644 --- a/src/EcsWorld.pools.cs +++ b/src/EcsWorld.pools.cs @@ -1,6 +1,5 @@ using DCFApixels.DragonECS.Internal; using System; -using System.Linq; using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS @@ -106,8 +105,9 @@ namespace DCFApixels.DragonECS { Throw.World_PoolAlreadyCreated(); } + TPool newPool = new TPool(); - Type componentType = typeof(TPool).GetInterfaces().First(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IEcsPoolImplementation<>)).GetGenericArguments()[0]; + Type componentType = newPool.ComponentType; int componentTypeCode = EcsTypeCode.Get(componentType); if (_componentTypeCode_2_CmpTypeIDs.TryGetValue(componentTypeCode, out int componentTypeID)) @@ -134,13 +134,14 @@ namespace DCFApixels.DragonECS } } - if (_pools[componentTypeID] == _nullPool) + if (_pools[componentTypeID] != _nullPool) { - var pool = new TPool(); - _pools[componentTypeID] = pool; - pool.OnInit(this, _poolsMediator, componentTypeID); + Throw.UndefinedException(); } - return (TPool)_pools[componentTypeID]; + + _pools[componentTypeID] = newPool; + newPool.OnInit(this, _poolsMediator, componentTypeID); + return newPool; } #endregion