mirror of
https://github.com/Ellpeck/Coroutine.git
synced 2024-11-21 21:33:29 +01:00
use default initial capacity when creating event coroutine collection
This commit is contained in:
parent
1e8a9e4e6c
commit
19e8a74d2b
1 changed files with 6 additions and 6 deletions
|
@ -96,7 +96,7 @@ namespace Coroutine {
|
||||||
/// <param name="evt">The event to raise</param>
|
/// <param name="evt">The event to raise</param>
|
||||||
public void RaiseEvent(Event evt) {
|
public void RaiseEvent(Event evt) {
|
||||||
this.MoveOutstandingCoroutines();
|
this.MoveOutstandingCoroutines();
|
||||||
var coroutines = this.GetEventCoroutines(evt, 0);
|
var coroutines = this.GetEventCoroutines(evt, false);
|
||||||
if (coroutines != null) {
|
if (coroutines != null) {
|
||||||
for (var i = 0; i < coroutines.Count; i++) {
|
for (var i = 0; i < coroutines.Count; i++) {
|
||||||
var c = coroutines[i];
|
var c = coroutines[i];
|
||||||
|
@ -123,20 +123,20 @@ namespace Coroutine {
|
||||||
private void MoveOutstandingCoroutines() {
|
private void MoveOutstandingCoroutines() {
|
||||||
// RemoveWhere is twice as fast as iterating and then clearing
|
// RemoveWhere is twice as fast as iterating and then clearing
|
||||||
this.eventCoroutinesToRemove.RemoveWhere(c => {
|
this.eventCoroutinesToRemove.RemoveWhere(c => {
|
||||||
this.GetEventCoroutines(c.Event, 0).Remove(c);
|
this.GetEventCoroutines(c.Event, false).Remove(c);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
this.outstandingCoroutines.RemoveWhere(c => {
|
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);
|
var position = list.BinarySearch(c);
|
||||||
list.Insert(position < 0 ? ~position : position, c);
|
list.Insert(position < 0 ? ~position : position, c);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ActiveCoroutine> GetEventCoroutines(Event evt, int capacity) {
|
private List<ActiveCoroutine> GetEventCoroutines(Event evt, bool create) {
|
||||||
if (!this.eventCoroutines.TryGetValue(evt, out var ret) && capacity > 0) {
|
if (!this.eventCoroutines.TryGetValue(evt, out var ret) && create) {
|
||||||
ret = new List<ActiveCoroutine>(capacity);
|
ret = new List<ActiveCoroutine>();
|
||||||
this.eventCoroutines.Add(evt, ret);
|
this.eventCoroutines.Add(evt, ret);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in a new issue