From 3bb446556a3b0677e39ff79b2e943f991682647a Mon Sep 17 00:00:00 2001 From: RamType0 Date: Fri, 28 Aug 2020 18:03:22 +0900 Subject: [PATCH] Use ref T for ITaskPoolNode.NextNode --- src/UniTask.NetCore/NetCore/UniTask.Yield.cs | 3 +- .../UniTask/Runtime/AsyncReactiveProperty.cs | 6 ++-- .../CompilerServices/StateMachineRunner.cs | 9 ++++-- .../Runtime/EnumeratorAsyncExtensions.cs | 3 +- .../Runtime/Internal/PooledDelegate.cs | 3 +- .../Plugins/UniTask/Runtime/TaskPool.cs | 7 +++-- .../Plugins/UniTask/Runtime/UniTask.Delay.cs | 18 +++++++---- .../UniTask/Runtime/UniTask.Threading.cs | 3 +- .../UniTask/Runtime/UniTask.WaitUntil.cs | 15 ++++++---- .../Runtime/UniTaskCompletionSource.cs | 6 ++-- ...cExtensions.AssetBundleRequestAllAssets.cs | 6 ++-- .../UnityAsyncExtensions.AsyncGPUReadback.cs | 3 +- .../UniTask/Runtime/UnityAsyncExtensions.cs | 30 ++++++++++++------- 13 files changed, 74 insertions(+), 38 deletions(-) diff --git a/src/UniTask.NetCore/NetCore/UniTask.Yield.cs b/src/UniTask.NetCore/NetCore/UniTask.Yield.cs index 4a39153..ee93c00 100644 --- a/src/UniTask.NetCore/NetCore/UniTask.Yield.cs +++ b/src/UniTask.NetCore/NetCore/UniTask.Yield.cs @@ -62,7 +62,8 @@ namespace Cysharp.Threading.Tasks sealed class ThreadPoolWorkItem : IThreadPoolWorkItem, ITaskPoolNode { static TaskPool pool; - public ThreadPoolWorkItem NextNode { get; set; } + ThreadPoolWorkItem nextNode; + public ref ThreadPoolWorkItem NextNode => ref nextNode; static ThreadPoolWorkItem() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs index 18a9a68..a08844d 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/AsyncReactiveProperty.cs @@ -87,7 +87,8 @@ namespace Cysharp.Threading.Tasks static Action cancellationCallback = CancellationCallback; static TaskPool pool; - WaitAsyncSource ITaskPoolNode.NextNode { get; set; } + WaitAsyncSource nextNode; + ref WaitAsyncSource ITaskPoolNode.NextNode => ref nextNode; static WaitAsyncSource() { @@ -404,7 +405,8 @@ namespace Cysharp.Threading.Tasks static Action cancellationCallback = CancellationCallback; static TaskPool pool; - WaitAsyncSource ITaskPoolNode.NextNode { get; set; } + WaitAsyncSource nextNode; + ref WaitAsyncSource ITaskPoolNode.NextNode => ref nextNode; static WaitAsyncSource() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs index 6507f41..1cffece 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/CompilerServices/StateMachineRunner.cs @@ -87,7 +87,8 @@ namespace Cysharp.Threading.Tasks.CompilerServices TaskPool.RegisterSizeGetter(typeof(AsyncUniTaskVoid), () => pool.Size); } - public AsyncUniTaskVoid NextNode { get; set; } + AsyncUniTaskVoid nextNode; + public ref AsyncUniTaskVoid NextNode => ref nextNode; public void Return() { @@ -157,7 +158,8 @@ namespace Cysharp.Threading.Tasks.CompilerServices result.stateMachine = stateMachine; // copy struct StateMachine(in release build). } - public AsyncUniTask NextNode { get; set; } + AsyncUniTask nextNode; + public ref AsyncUniTask NextNode => ref nextNode; static AsyncUniTask() { @@ -279,7 +281,8 @@ namespace Cysharp.Threading.Tasks.CompilerServices result.stateMachine = stateMachine; // copy struct StateMachine(in release build). } - public AsyncUniTask NextNode { get; set; } + AsyncUniTask nextNode; + public ref AsyncUniTask NextNode => ref nextNode; static AsyncUniTask() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs index 36dca5a..4722b47 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/EnumeratorAsyncExtensions.cs @@ -35,7 +35,8 @@ namespace Cysharp.Threading.Tasks sealed class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public EnumeratorPromise NextNode { get; set; } + EnumeratorPromise nextNode; + public ref EnumeratorPromise NextNode => ref nextNode; static EnumeratorPromise() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs index 8d76d98..518244f 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs @@ -7,7 +7,8 @@ namespace Cysharp.Threading.Tasks.Internal { static TaskPool> pool; - public PooledDelegate NextNode { get; set; } + PooledDelegate nextNode; + public ref PooledDelegate NextNode => ref nextNode; static PooledDelegate() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/TaskPool.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/TaskPool.cs index 57fa7cb..8bae491 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/TaskPool.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/TaskPool.cs @@ -55,7 +55,7 @@ namespace Cysharp.Threading.Tasks public interface ITaskPoolNode { - T NextNode { get; set; } + ref T NextNode { get; } } // mutable struct, don't mark readonly. @@ -77,8 +77,9 @@ namespace Cysharp.Threading.Tasks var v = root; if (!(v is null)) { - root = v.NextNode; - v.NextNode = null; + ref var nextNode = ref v.NextNode; + root = nextNode; + nextNode = null; size--; result = v; Volatile.Write(ref gate, 0); diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs index 8a9ed14..d89dd5e 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Delay.cs @@ -127,7 +127,8 @@ namespace Cysharp.Threading.Tasks sealed class YieldPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public YieldPromise NextNode { get; set; } + YieldPromise nextNode; + public ref YieldPromise NextNode => ref nextNode; static YieldPromise() { @@ -215,7 +216,8 @@ namespace Cysharp.Threading.Tasks sealed class NextFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public NextFramePromise NextNode { get; set; } + NextFramePromise nextNode; + public ref NextFramePromise NextNode => ref nextNode; static NextFramePromise() { @@ -309,7 +311,8 @@ namespace Cysharp.Threading.Tasks sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public DelayFramePromise NextNode { get; set; } + DelayFramePromise nextNode; + public ref DelayFramePromise NextNode => ref nextNode; static DelayFramePromise() { @@ -424,7 +427,8 @@ namespace Cysharp.Threading.Tasks sealed class DelayPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public DelayPromise NextNode { get; set; } + DelayPromise nextNode; + public ref DelayPromise NextNode => ref nextNode; static DelayPromise() { @@ -534,7 +538,8 @@ namespace Cysharp.Threading.Tasks sealed class DelayIgnoreTimeScalePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public DelayIgnoreTimeScalePromise NextNode { get; set; } + DelayIgnoreTimeScalePromise nextNode; + public ref DelayIgnoreTimeScalePromise NextNode => ref nextNode; static DelayIgnoreTimeScalePromise() { @@ -644,7 +649,8 @@ namespace Cysharp.Threading.Tasks sealed class DelayRealtimePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public DelayRealtimePromise NextNode { get; set; } + DelayRealtimePromise nextNode; + public ref DelayRealtimePromise NextNode => ref nextNode; static DelayRealtimePromise() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs index 4735dad..71d6aec 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.Threading.cs @@ -224,7 +224,8 @@ namespace Cysharp.Threading.Tasks sealed class ThreadPoolWorkItem : IThreadPoolWorkItem, ITaskPoolNode { static TaskPool pool; - public ThreadPoolWorkItem NextNode { get; set; } + ThreadPoolWorkItem nextNode; + public ref ThreadPoolWorkItem NextNode => ref nextNode; static ThreadPoolWorkItem() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs index 6228311..0a09fe0 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.WaitUntil.cs @@ -38,7 +38,8 @@ namespace Cysharp.Threading.Tasks sealed class WaitUntilPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public WaitUntilPromise NextNode { get; set; } + WaitUntilPromise nextNode; + public ref WaitUntilPromise NextNode => ref nextNode; static WaitUntilPromise() { @@ -142,7 +143,8 @@ namespace Cysharp.Threading.Tasks sealed class WaitWhilePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public WaitWhilePromise NextNode { get; set; } + WaitWhilePromise nextNode; + public ref WaitWhilePromise NextNode => ref nextNode; static WaitWhilePromise() { @@ -246,7 +248,8 @@ namespace Cysharp.Threading.Tasks sealed class WaitUntilCanceledPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public WaitUntilCanceledPromise NextNode { get; set; } + WaitUntilCanceledPromise nextNode; + public ref WaitUntilCanceledPromise NextNode => ref nextNode; static WaitUntilCanceledPromise() { @@ -334,7 +337,8 @@ namespace Cysharp.Threading.Tasks sealed class WaitUntilValueChangedUnityObjectPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode> { static TaskPool> pool; - public WaitUntilValueChangedUnityObjectPromise NextNode { get; set; } + WaitUntilValueChangedUnityObjectPromise nextNode; + public ref WaitUntilValueChangedUnityObjectPromise NextNode => ref nextNode; static WaitUntilValueChangedUnityObjectPromise() { @@ -457,7 +461,8 @@ namespace Cysharp.Threading.Tasks where T : class { static TaskPool> pool; - public WaitUntilValueChangedStandardObjectPromise NextNode { get; set; } + WaitUntilValueChangedStandardObjectPromise nextNode; + public ref WaitUntilValueChangedStandardObjectPromise NextNode => ref nextNode; static WaitUntilValueChangedStandardObjectPromise() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs index 30ffd87..67b882e 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UniTaskCompletionSource.cs @@ -319,7 +319,8 @@ namespace Cysharp.Threading.Tasks public class AutoResetUniTaskCompletionSource : IUniTaskSource, ITaskPoolNode, IPromise { static TaskPool pool; - public AutoResetUniTaskCompletionSource NextNode { get; set; } + AutoResetUniTaskCompletionSource nextNode; + public ref AutoResetUniTaskCompletionSource NextNode => ref nextNode; static AutoResetUniTaskCompletionSource() { @@ -441,7 +442,8 @@ namespace Cysharp.Threading.Tasks public class AutoResetUniTaskCompletionSource : IUniTaskSource, ITaskPoolNode>, IPromise { static TaskPool> pool; - public AutoResetUniTaskCompletionSource NextNode { get; set; } + AutoResetUniTaskCompletionSource nextNode; + public ref AutoResetUniTaskCompletionSource NextNode => ref nextNode; static AutoResetUniTaskCompletionSource() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs index 076d255..3a19a47 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AssetBundleRequestAllAssets.cs @@ -82,7 +82,8 @@ namespace Cysharp.Threading.Tasks sealed class AssetBundleRequestAllAssetsWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AssetBundleRequestAllAssetsWithCancellationSource NextNode { get; set; } + AssetBundleRequestAllAssetsWithCancellationSource nextNode; + public ref AssetBundleRequestAllAssetsWithCancellationSource NextNode => ref nextNode; static AssetBundleRequestAllAssetsWithCancellationSource() { @@ -204,7 +205,8 @@ namespace Cysharp.Threading.Tasks sealed class AssetBundleRequestAllAssetsConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AssetBundleRequestAllAssetsConfiguredSource NextNode { get; set; } + AssetBundleRequestAllAssetsConfiguredSource nextNode; + public ref AssetBundleRequestAllAssetsConfiguredSource NextNode => ref nextNode; static AssetBundleRequestAllAssetsConfiguredSource() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs index 7c8e5ff..2be6f1f 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.AsyncGPUReadback.cs @@ -29,7 +29,8 @@ namespace Cysharp.Threading.Tasks sealed class AsyncGPUReadbackRequestAwaiterConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AsyncGPUReadbackRequestAwaiterConfiguredSource NextNode { get; set; } + AsyncGPUReadbackRequestAwaiterConfiguredSource nextNode; + public ref AsyncGPUReadbackRequestAwaiterConfiguredSource NextNode => ref nextNode; static AsyncGPUReadbackRequestAwaiterConfiguredSource() { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs index 5246bc1..33c8694 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/UnityAsyncExtensions.cs @@ -80,7 +80,8 @@ namespace Cysharp.Threading.Tasks sealed class AsyncOperationWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AsyncOperationWithCancellationSource NextNode { get; set; } + AsyncOperationWithCancellationSource nextNode; + public ref AsyncOperationWithCancellationSource NextNode => ref nextNode; static AsyncOperationWithCancellationSource() { @@ -198,7 +199,8 @@ namespace Cysharp.Threading.Tasks sealed class AsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AsyncOperationConfiguredSource NextNode { get; set; } + AsyncOperationConfiguredSource nextNode; + public ref AsyncOperationConfiguredSource NextNode => ref nextNode; static AsyncOperationConfiguredSource() { @@ -374,7 +376,8 @@ namespace Cysharp.Threading.Tasks sealed class ResourceRequestWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public ResourceRequestWithCancellationSource NextNode { get; set; } + ResourceRequestWithCancellationSource nextNode; + public ref ResourceRequestWithCancellationSource NextNode => ref nextNode; static ResourceRequestWithCancellationSource() { @@ -496,7 +499,8 @@ namespace Cysharp.Threading.Tasks sealed class ResourceRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public ResourceRequestConfiguredSource NextNode { get; set; } + ResourceRequestConfiguredSource nextNode; + public ref ResourceRequestConfiguredSource NextNode => ref nextNode; static ResourceRequestConfiguredSource() { @@ -677,7 +681,8 @@ namespace Cysharp.Threading.Tasks sealed class AssetBundleRequestWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AssetBundleRequestWithCancellationSource NextNode { get; set; } + AssetBundleRequestWithCancellationSource nextNode; + public ref AssetBundleRequestWithCancellationSource NextNode => ref nextNode; static AssetBundleRequestWithCancellationSource() { @@ -799,7 +804,8 @@ namespace Cysharp.Threading.Tasks sealed class AssetBundleRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AssetBundleRequestConfiguredSource NextNode { get; set; } + AssetBundleRequestConfiguredSource nextNode; + public ref AssetBundleRequestConfiguredSource NextNode => ref nextNode; static AssetBundleRequestConfiguredSource() { @@ -981,7 +987,8 @@ namespace Cysharp.Threading.Tasks sealed class AssetBundleCreateRequestWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AssetBundleCreateRequestWithCancellationSource NextNode { get; set; } + AssetBundleCreateRequestWithCancellationSource nextNode; + public ref AssetBundleCreateRequestWithCancellationSource NextNode => ref nextNode; static AssetBundleCreateRequestWithCancellationSource() { @@ -1103,7 +1110,8 @@ namespace Cysharp.Threading.Tasks sealed class AssetBundleCreateRequestConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public AssetBundleCreateRequestConfiguredSource NextNode { get; set; } + AssetBundleCreateRequestConfiguredSource nextNode; + public ref AssetBundleCreateRequestConfiguredSource NextNode => ref nextNode; static AssetBundleCreateRequestConfiguredSource() { @@ -1307,7 +1315,8 @@ namespace Cysharp.Threading.Tasks sealed class UnityWebRequestAsyncOperationWithCancellationSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public UnityWebRequestAsyncOperationWithCancellationSource NextNode { get; set; } + UnityWebRequestAsyncOperationWithCancellationSource nextNode; + public ref UnityWebRequestAsyncOperationWithCancellationSource NextNode => ref nextNode; static UnityWebRequestAsyncOperationWithCancellationSource() { @@ -1438,7 +1447,8 @@ namespace Cysharp.Threading.Tasks sealed class UnityWebRequestAsyncOperationConfiguredSource : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode { static TaskPool pool; - public UnityWebRequestAsyncOperationConfiguredSource NextNode { get; set; } + UnityWebRequestAsyncOperationConfiguredSource nextNode; + public ref UnityWebRequestAsyncOperationConfiguredSource NextNode => ref nextNode; static UnityWebRequestAsyncOperationConfiguredSource() {