From 0551aa0a073af5f32320cece0ea3ba17c647633d Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 7 Nov 2023 18:12:42 -0800 Subject: [PATCH] don't copy array data over itself --- src/Collections/IndexableSet.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Collections/IndexableSet.cs b/src/Collections/IndexableSet.cs index d49c597..140f9f5 100644 --- a/src/Collections/IndexableSet.cs +++ b/src/Collections/IndexableSet.cs @@ -61,10 +61,14 @@ namespace MoonTools.ECS.Collections return false; } - var lastElement = array[Count - 1]; var index = indices[element]; - array[index] = lastElement; - indices[lastElement] = index; + + if (index != Count - 1) + { + var lastElement = array[Count - 1]; + array[index] = lastElement; + indices[lastElement] = index; + } count -= 1; indices.Remove(element);