Merge pull request #157 from RamType-0/OptimizeConsumeEnumerator

Optimize EnumeratorPromise.ConsumeEnumerator while consuming CustomYieldInstruction
master
Yoshifumi Kawai 2020-09-07 17:23:08 +09:00 committed by GitHub
commit 4955ed18f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 12 deletions

View File

@ -163,11 +163,10 @@ namespace Cysharp.Threading.Tasks
{ {
yield return null; yield return null;
} }
else if (current is CustomYieldInstruction) else if (current is CustomYieldInstruction cyi)
{ {
// WWW, WaitForSecondsRealtime // WWW, WaitForSecondsRealtime
var e2 = UnwrapWaitCustomYieldInstruction((CustomYieldInstruction)current); while (cyi.keepWaiting)
while (e2.MoveNext())
{ {
yield return null; yield return null;
} }
@ -212,15 +211,6 @@ namespace Cysharp.Threading.Tasks
} }
} }
// WWW and others as CustomYieldInstruction.
static IEnumerator UnwrapWaitCustomYieldInstruction(CustomYieldInstruction yieldInstruction)
{
while (yieldInstruction.keepWaiting)
{
yield return null;
}
}
static readonly FieldInfo waitForSeconds_Seconds = typeof(WaitForSeconds).GetField("m_Seconds", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic); static readonly FieldInfo waitForSeconds_Seconds = typeof(WaitForSeconds).GetField("m_Seconds", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
static IEnumerator UnwrapWaitForSeconds(WaitForSeconds waitForSeconds) static IEnumerator UnwrapWaitForSeconds(WaitForSeconds waitForSeconds)