Merge pull request #7488 from RoosterDragon/trait-remove-perf

Speed up TraitContainer.RemoveActor.
This commit is contained in:
Paul Chote
2015-02-20 17:45:40 +00:00

View File

@@ -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);
} }
} }
} }