Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andreakarasho committed Mar 9, 2024
1 parent 04a7e7a commit 7fd1dd8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Archetype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ internal ref ArchetypeChunk GetChunk(int index)
index /= CHUNK_THRESHOLD;

if (index >= _chunks.Length)
Array.Resize(ref _chunks, _chunks.Length * 2);
Array.Resize(ref _chunks, Math.Max(ARCHETYPE_INITIAL_CAPACITY, _chunks.Length * 2));

ref var chunk = ref _chunks[index];
if (chunk.Components == null)
Expand Down Expand Up @@ -198,6 +198,13 @@ internal int MoveEntity(Archetype to, int fromRow)

--_count;


// Cleanup
var empty = EmptyChunks;
var half = Math.Max(ARCHETYPE_INITIAL_CAPACITY, _chunks.Length / 2);
if (empty > half)
Array.Resize(ref _chunks, half);

return toRow;
}

Expand Down

0 comments on commit 7fd1dd8

Please sign in to comment.