From 75abc8059f97d2571fb8dfc96841ebabb8a0e2f9 Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" Date: Tue, 1 Sep 2020 21:18:13 +0900 Subject: [PATCH 1/3] 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) From 725b2fdc35b4e6b37ffc32714f41059486269292 Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" Date: Tue, 1 Sep 2020 21:25:43 +0900 Subject: [PATCH 2/3] Format comment --- .../Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs index e9951fc..3d018a3 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs @@ -164,8 +164,9 @@ namespace Cysharp.Threading.Tasks } else if (current is CustomYieldInstruction cyi) { + //https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Scripting/CustomYieldInstruction.cs // WWW, WaitForSecondsRealtime - while (cyi.keepWaiting)//https://github.com/Unity-Technologies/UnityCsReference/blob/4fc5eb0fb2c7f5fb09f990fc99f162c8d06d9570/Runtime/Export/Scripting/CustomYieldInstruction.cs + while (cyi.keepWaiting)//Use keepWaiting instead of MoveNext to avoid virtual call { yield return null; } From 227f7872cb028b99ec88ce2f010626fe854a3d83 Mon Sep 17 00:00:00 2001 From: RamType0 Date: Wed, 2 Sep 2020 13:19:11 +0900 Subject: [PATCH 3/3] Remove comments --- .../Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs index 3d018a3..c324f14 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs @@ -164,9 +164,8 @@ namespace Cysharp.Threading.Tasks } else if (current is CustomYieldInstruction cyi) { - //https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Export/Scripting/CustomYieldInstruction.cs // WWW, WaitForSecondsRealtime - while (cyi.keepWaiting)//Use keepWaiting instead of MoveNext to avoid virtual call + while (cyi.keepWaiting) { yield return null; }