using System; using System.Collections.Generic; using UnityEngine; namespace litefeel.Finder.Editor { internal static class ListPool { // Object pool to avoid allocations. private static readonly ObjectPool> s_ListPool = new ObjectPool>(null, Clear); static void Clear(List l) { l.Clear(); } public static List Get() { return s_ListPool.Get(); } public static void Release(List toRelease) { s_ListPool.Release(toRelease); } } public struct ListPoolScope : IDisposable { private bool m_Disposed; public readonly List list; private ListPoolScope(List list) { m_Disposed = false; this.list = list; } public void Dispose() { if (m_Disposed) return; m_Disposed = true; ListPool.Release(list); } public static ListPoolScope Create() { return new ListPoolScope(ListPool.Get()); } } }