use default initial capacity when creating event coroutine collection

This commit is contained in:
Ell 2021-03-20 21:21:05 +01:00
parent 1e8a9e4e6c
commit 19e8a74d2b
1 changed files with 6 additions and 6 deletions

View File

@ -96,7 +96,7 @@ namespace Coroutine {
/// <param name="evt">The event to raise</param>
public void RaiseEvent(Event evt) {
this.MoveOutstandingCoroutines();
var coroutines = this.GetEventCoroutines(evt, 0);
var coroutines = this.GetEventCoroutines(evt, false);
if (coroutines != null) {
for (var i = 0; i < coroutines.Count; i++) {
var c = coroutines[i];
@ -123,20 +123,20 @@ namespace Coroutine {
private void MoveOutstandingCoroutines() {
// RemoveWhere is twice as fast as iterating and then clearing
this.eventCoroutinesToRemove.RemoveWhere(c => {
this.GetEventCoroutines(c.Event, 0).Remove(c);
this.GetEventCoroutines(c.Event, false).Remove(c);
return true;
});
this.outstandingCoroutines.RemoveWhere(c => {
var list = c.IsWaitingForEvent ? this.GetEventCoroutines(c.Event, 1) : this.tickingCoroutines;
var list = c.IsWaitingForEvent ? this.GetEventCoroutines(c.Event, true) : this.tickingCoroutines;
var position = list.BinarySearch(c);
list.Insert(position < 0 ? ~position : position, c);
return true;
});
}
private List<ActiveCoroutine> GetEventCoroutines(Event evt, int capacity) {
if (!this.eventCoroutines.TryGetValue(evt, out var ret) && capacity > 0) {
ret = new List<ActiveCoroutine>(capacity);
private List<ActiveCoroutine> GetEventCoroutines(Event evt, bool create) {
if (!this.eventCoroutines.TryGetValue(evt, out var ret) && create) {
ret = new List<ActiveCoroutine>();
this.eventCoroutines.Add(evt, ret);
}
return ret;