Skip to content

Commit

Permalink
Optimize clearing array by using Array.Fill (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-000 authored Feb 5, 2025
1 parent 804423a commit 86507ba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/Arch/Buffer/SparseSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,7 @@ public ref T Get<T>(int index)
/// </summary>
public void Clear()
{
for (var index = 0; index < Entities.Length; index++)
{
Entities[index] = -1;
}
Array.Fill(Entities, -1, 0, Entities.Length);
Size = 0;
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/Arch/Buffer/StructuralSparseSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ public bool Contains(int index)
/// </summary>
public void Clear()
{
for (var index = 0; index < Entities.Length; index++)
{
Entities[index] = -1;
}
Array.Fill(Entities, -1, 0, Size);
Size = 0;
}
}
Expand Down

0 comments on commit 86507ba

Please sign in to comment.