From b6e43f98fb36ea0cc25c6d311adf32ae6248a97e Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 17 Mar 2026 10:27:48 +0800 Subject: [PATCH] fix mem alloc --- src/Executors/EcsWhereExecutor.cs | 8 ++++---- src/Internal/Allocators/MemoryAllocator.cs | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Executors/EcsWhereExecutor.cs b/src/Executors/EcsWhereExecutor.cs index 529bfd0..3b71fcd 100644 --- a/src/Executors/EcsWhereExecutor.cs +++ b/src/Executors/EcsWhereExecutor.cs @@ -97,8 +97,8 @@ namespace DCFApixels.DragonECS.Core.Internal public EcsUnsafeSpan Execute() { Execute_Iternal(); - var result = new EcsUnsafeSpan(World.ID, _filteredAllEntities.Ptr, _filteredAllEntitiesCount); #if DEBUG && DRAGONECS_DEEP_DEBUG + var result = new EcsUnsafeSpan(World.ID, _filteredAllEntities.Ptr, _filteredAllEntitiesCount); using (EcsGroup group = EcsGroup.New(World)) { foreach (var e in World.Entities) @@ -119,7 +119,7 @@ namespace DCFApixels.DragonECS.Core.Internal } } #endif - return result; + return new EcsUnsafeSpan(World.ID, _filteredAllEntities.Ptr, _filteredAllEntitiesCount); ; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public EcsUnsafeSpan ExecuteFor(EcsSpan span) @@ -129,8 +129,8 @@ namespace DCFApixels.DragonECS.Core.Internal return Execute(); } ExecuteFor_Iternal(span); - var result = new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount); #if DEBUG && DRAGONECS_DEEP_DEBUG + var result = new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount); foreach (var e in result) { if (World.IsMatchesMask(Mask, e) == false) @@ -139,7 +139,7 @@ namespace DCFApixels.DragonECS.Core.Internal } } #endif - return result; + return new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount); ; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Internal/Allocators/MemoryAllocator.cs b/src/Internal/Allocators/MemoryAllocator.cs index 656f9fb..9f4f130 100644 --- a/src/Internal/Allocators/MemoryAllocator.cs +++ b/src/Internal/Allocators/MemoryAllocator.cs @@ -278,6 +278,7 @@ namespace DCFApixels.DragonECS.Core.Internal public readonly T* Ptr; public readonly int Length; + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal HMem(Handler handler, int length) { Ptr = handler.As(); @@ -300,8 +301,8 @@ namespace DCFApixels.DragonECS.Core.Internal get { return Handler.FromDataPtr(Ptr); } } - public HMem As() - where U : unmanaged + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public HMem As() where U : unmanaged { if (IsCreated) { @@ -329,7 +330,7 @@ namespace DCFApixels.DragonECS.Core.Internal } #if DEBUG - public override string ToString() { return DebuggerDisplay(); } + public override string ToString() { return Handler.DebuggerDisplay(); } #endif [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() { return RawPtr.GetHashCode(); } @@ -342,7 +343,9 @@ namespace DCFApixels.DragonECS.Core.Internal [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator !=(HMem a, HMem b) { return a.Ptr != b.Ptr; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AsSpan() { return new Span(Ptr, Length); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span AsSpan(int length) { #if DEBUG @@ -350,6 +353,7 @@ namespace DCFApixels.DragonECS.Core.Internal #endif return new Span(Ptr, length); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator Handler(HMem memory) { return memory.Handler; } }