/
GeekNerd
/
ServerModelingProject
Обзор
Документация
Войти
/
GeekNerd
/
ServerModelingProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Assets/Plugins/UniTask/Runtime/Internal/PooledDelegate.cs
50 строк
1 KB
Gorney-Alex
Init
30 май 2026, 19:05
30 май 2026, 19:05
3cdcc49
Код
Авторство
О чём код?
using System; using System.Runtime.CompilerServices; namespace Cysharp.Threading.Tasks.Internal { internal sealed class PooledDelegate<T> : ITaskPoolNode<PooledDelegate<T>> { static TaskPool<PooledDelegate<T>> pool; PooledDelegate<T> nextNode; public ref PooledDelegate<T> NextNode => ref nextNode; static PooledDelegate() { TaskPool.RegisterSizeGetter(typeof(PooledDelegate<T>), () => pool.Size); } readonly Action<T> runDelegate; Action continuation; PooledDelegate() { runDelegate = Run; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Action<T> Create(Action continuation) { if (!pool.TryPop(out var item)) { item = new PooledDelegate<T>(); } item.continuation = continuation; return item.runDelegate; } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Run(T _) { var call = continuation; continuation = null; if (call != null) { pool.TryPush(this); call.Invoke(); } } } }