Merge pull request #203 from RamType0/FixCompletedTaskAsUniTaskAllocating

Suppress allocations around UniTask<T>.AsUniTask and UniTask.AsAsyncUnitUniTask
master
Yoshifumi Kawai 2021-01-06 17:19:19 +09:00 committed by GitHub
commit 9406305b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
} }