diff --git a/src/Collections/NativeArray.cs b/src/Collections/NativeArray.cs index 10e48ca..a0af02a 100644 --- a/src/Collections/NativeArray.cs +++ b/src/Collections/NativeArray.cs @@ -11,6 +11,7 @@ public unsafe class NativeArray : IDisposable where T : unmanaged private int Capacity; private int ElementSize; + public Span ToSpan() => new Span(Elements, Count); public Span.Enumerator GetEnumerator() => new Span(Elements, Count).GetEnumerator(); private bool disposed; @@ -71,11 +72,7 @@ public unsafe class NativeArray : IDisposable where T : unmanaged { if (index != Count - 1) { - NativeMemory.Copy( - (void*) (Elements + ((Count - 1) * ElementSize)), - (void*) (Elements + (index * ElementSize)), - (nuint) ElementSize - ); + this[index] = this[Count - 1]; } Count -= 1; diff --git a/src/RelationStorage.cs b/src/RelationStorage.cs index ee70bbf..31a12fa 100644 --- a/src/RelationStorage.cs +++ b/src/RelationStorage.cs @@ -171,9 +171,6 @@ internal class RelationStorage { var lastElementIndex = relations.Count - 1; - relationDatas.Delete(index); - relations.Delete(index); - // move an element into the hole if (index != lastElementIndex) { @@ -181,6 +178,9 @@ internal class RelationStorage indices[lastRelation] = index; } + relationDatas.Delete(index); + relations.Delete(index); + indices.Remove(relation); }