Suppress allocations around UniTask<T>.AsUniTask and UniTask.AsAsyncUnitUniTask

- Fix completedTask.AsUniTask or completedTask.AsAsyncUnitUniTask leaks IUniTaskSource
- UniTask.AsAsyncUnitUniTask no longer allocates when its inner IUniTaskSource is IUniTaskSource<AsyncUnit>
master
RamType0 2020-12-17 14:28:10 +09:00
parent 3115efb672
commit a455de88b0
1 changed files with 6 additions and 0 deletions

View File

@ -115,8 +115,13 @@ namespace Cysharp.Threading.Tasks
var status = this.source.GetStatus(this.token); var status = this.source.GetStatus(this.token);
if (status.IsCompletedSuccessfully()) if (status.IsCompletedSuccessfully())
{ {
this.source.GetResult(this.token);
return CompletedTasks.AsyncUnit; return CompletedTasks.AsyncUnit;
} }
else if(this.source is IUniTaskSource<AsyncUnit> asyncUnitSource)
{
return new UniTask<AsyncUnit>(asyncUnitSource, this.token);
}
return new UniTask<AsyncUnit>(new AsyncUnitSource(this.source), this.token); return new UniTask<AsyncUnit>(new AsyncUnitSource(this.source), this.token);
} }
@ -422,6 +427,7 @@ namespace Cysharp.Threading.Tasks
var status = this.source.GetStatus(this.token); var status = this.source.GetStatus(this.token);
if (status.IsCompletedSuccessfully()) if (status.IsCompletedSuccessfully())
{ {
this.source.GetResult(this.token);
return UniTask.CompletedTask; return UniTask.CompletedTask;
} }