From 53f4124fdb5495ec309f093055cc3dbcddc9917e Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Fri, 3 Nov 2023 16:51:26 -0700 Subject: [PATCH] stupid ass pointer math --- src/Collections/NativeArray.cs | 7 ++----- src/RelationStorage.cs | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) 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); }