Speed up TraitContainer.RemoveActor.

Use the binary search invariant of the lists to find the actor quickly and remove the range of entries from the list in a single operation to avoid redundant copying otherwise caused by removing entries one by one.
This commit is contained in:
RoosterDragon
2015-02-14 00:39:03 +00:00
parent 32411d64df
commit a3898db660

View File

@@ -231,14 +231,15 @@ namespace OpenRA
public void RemoveActor(uint actor)
{
for (var i = actors.Count - 1; i >= 0; i--)
{
if (actors[i].ActorID == actor)
{
actors.RemoveAt(i);
traits.RemoveAt(i);
}
}
var startIndex = actors.BinarySearchMany(actor);
if (startIndex >= actors.Count || actors[startIndex].ActorID != actor)
return;
var endIndex = startIndex + 1;
while (endIndex < actors.Count && actors[endIndex].ActorID == actor)
endIndex++;
var count = endIndex - startIndex;
actors.RemoveRange(startIndex, count);
traits.RemoveRange(startIndex, count);
}
}
}