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:
@@ -231,14 +231,15 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void RemoveActor(uint actor)
|
public void RemoveActor(uint actor)
|
||||||
{
|
{
|
||||||
for (var i = actors.Count - 1; i >= 0; i--)
|
var startIndex = actors.BinarySearchMany(actor);
|
||||||
{
|
if (startIndex >= actors.Count || actors[startIndex].ActorID != actor)
|
||||||
if (actors[i].ActorID == actor)
|
return;
|
||||||
{
|
var endIndex = startIndex + 1;
|
||||||
actors.RemoveAt(i);
|
while (endIndex < actors.Count && actors[endIndex].ActorID == actor)
|
||||||
traits.RemoveAt(i);
|
endIndex++;
|
||||||
}
|
var count = endIndex - startIndex;
|
||||||
}
|
actors.RemoveRange(startIndex, count);
|
||||||
|
traits.RemoveRange(startIndex, count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user