fix mem alloc

This commit is contained in:
Mikhail 2026-03-17 10:27:48 +08:00
parent b6953c919c
commit b6e43f98fb
2 changed files with 11 additions and 7 deletions

View File

@ -97,8 +97,8 @@ namespace DCFApixels.DragonECS.Core.Internal
public EcsUnsafeSpan Execute() public EcsUnsafeSpan Execute()
{ {
Execute_Iternal(); Execute_Iternal();
var result = new EcsUnsafeSpan(World.ID, _filteredAllEntities.Ptr, _filteredAllEntitiesCount);
#if DEBUG && DRAGONECS_DEEP_DEBUG #if DEBUG && DRAGONECS_DEEP_DEBUG
var result = new EcsUnsafeSpan(World.ID, _filteredAllEntities.Ptr, _filteredAllEntitiesCount);
using (EcsGroup group = EcsGroup.New(World)) using (EcsGroup group = EcsGroup.New(World))
{ {
foreach (var e in World.Entities) foreach (var e in World.Entities)
@ -119,7 +119,7 @@ namespace DCFApixels.DragonECS.Core.Internal
} }
} }
#endif #endif
return result; return new EcsUnsafeSpan(World.ID, _filteredAllEntities.Ptr, _filteredAllEntitiesCount); ;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public EcsUnsafeSpan ExecuteFor(EcsSpan span) public EcsUnsafeSpan ExecuteFor(EcsSpan span)
@ -129,8 +129,8 @@ namespace DCFApixels.DragonECS.Core.Internal
return Execute(); return Execute();
} }
ExecuteFor_Iternal(span); ExecuteFor_Iternal(span);
var result = new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount);
#if DEBUG && DRAGONECS_DEEP_DEBUG #if DEBUG && DRAGONECS_DEEP_DEBUG
var result = new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount);
foreach (var e in result) foreach (var e in result)
{ {
if (World.IsMatchesMask(Mask, e) == false) if (World.IsMatchesMask(Mask, e) == false)
@ -139,7 +139,7 @@ namespace DCFApixels.DragonECS.Core.Internal
} }
} }
#endif #endif
return result; return new EcsUnsafeSpan(World.ID, _filteredEntities.Ptr, _filteredEntitiesCount); ;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]

View File

@ -278,6 +278,7 @@ namespace DCFApixels.DragonECS.Core.Internal
public readonly T* Ptr; public readonly T* Ptr;
public readonly int Length; public readonly int Length;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal HMem(Handler handler, int length) internal HMem(Handler handler, int length)
{ {
Ptr = handler.As<T>(); Ptr = handler.As<T>();
@ -300,8 +301,8 @@ namespace DCFApixels.DragonECS.Core.Internal
get { return Handler.FromDataPtr(Ptr); } get { return Handler.FromDataPtr(Ptr); }
} }
public HMem<U> As<U>() [MethodImpl(MethodImplOptions.AggressiveInlining)]
where U : unmanaged public HMem<U> As<U>() where U : unmanaged
{ {
if (IsCreated) if (IsCreated)
{ {
@ -329,7 +330,7 @@ namespace DCFApixels.DragonECS.Core.Internal
} }
#if DEBUG #if DEBUG
public override string ToString() { return DebuggerDisplay(); } public override string ToString() { return Handler.DebuggerDisplay(); }
#endif #endif
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() { return RawPtr.GetHashCode(); } public override int GetHashCode() { return RawPtr.GetHashCode(); }
@ -342,7 +343,9 @@ namespace DCFApixels.DragonECS.Core.Internal
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(HMem<T> a, HMem<T> b) { return a.Ptr != b.Ptr; } public static bool operator !=(HMem<T> a, HMem<T> b) { return a.Ptr != b.Ptr; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan() { return new Span<T>(Ptr, Length); } public Span<T> AsSpan() { return new Span<T>(Ptr, Length); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan(int length) public Span<T> AsSpan(int length)
{ {
#if DEBUG #if DEBUG
@ -350,6 +353,7 @@ namespace DCFApixels.DragonECS.Core.Internal
#endif #endif
return new Span<T>(Ptr, length); return new Span<T>(Ptr, length);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator Handler(HMem<T> memory) { return memory.Handler; } public static implicit operator Handler(HMem<T> memory) { return memory.Handler; }
} }