From 75abc8059f97d2571fb8dfc96841ebabb8a0e2f9 Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" Date: Tue, 1 Sep 2020 21:18:13 +0900 Subject: [PATCH] Optimize EnumeratorPromise.ConsumeEnumerator while consuming CustomYieldInstruction --- .../UniTask/Runtime/EnumeratorAsyncExtensions.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs index 36dca5a..e9951fc 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs @@ -162,11 +162,10 @@ namespace Cysharp.Threading.Tasks { yield return null; } - else if (current is CustomYieldInstruction) + else if (current is CustomYieldInstruction cyi) { // WWW, WaitForSecondsRealtime - var e2 = UnwrapWaitCustomYieldInstruction((CustomYieldInstruction)current); - while (e2.MoveNext()) + while (cyi.keepWaiting)//https://github.com/Unity-Technologies/UnityCsReference/blob/4fc5eb0fb2c7f5fb09f990fc99f162c8d06d9570/Runtime/Export/Scripting/CustomYieldInstruction.cs { 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 IEnumerator UnwrapWaitForSeconds(WaitForSeconds waitForSeconds)