Optimize EnumeratorPromise.ConsumeEnumerator while consuming CustomYieldInstruction

master
Ram.Type-0 2020-09-01 21:18:13 +09:00
parent 4d554a6718
commit 75abc8059f
1 changed files with 2 additions and 12 deletions

View File

@ -162,11 +162,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)//https://github.com/Unity-Technologies/UnityCsReference/blob/4fc5eb0fb2c7f5fb09f990fc99f162c8d06d9570/Runtime/Export/Scripting/CustomYieldInstruction.cs
while (e2.MoveNext())
{ {
yield return null; yield return null;
} }
@ -211,15 +210,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)