1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System.Collections.Generic;
- namespace Pathfinding.Util {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static class StackPool<T> {
-
- static readonly List<Stack<T> > pool;
-
- static StackPool () {
- pool = new List<Stack<T> >();
- }
-
-
-
-
-
-
- public static Stack<T> Claim () {
- #if ASTAR_NO_POOLING
- return new Stack<T>();
- #else
- lock (pool) {
- if (pool.Count > 0) {
- Stack<T> ls = pool[pool.Count-1];
- pool.RemoveAt(pool.Count-1);
- return ls;
- }
- }
- return new Stack<T>();
- #endif
- }
-
-
-
-
- public static void Warmup (int count) {
- var tmp = new Stack<T>[count];
- for (int i = 0; i < count; i++) tmp[i] = Claim();
- for (int i = 0; i < count; i++) Release(tmp[i]);
- }
-
-
-
-
-
- public static void Release (Stack<T> stack) {
- #if !ASTAR_NO_POOLING
- stack.Clear();
- lock (pool) {
- for (int i = 0; i < pool.Count; i++)
- if (pool[i] == stack) UnityEngine.Debug.LogError("The Stack is released even though it is inside the pool");
- pool.Add(stack);
- }
- #endif
- }
-
-
-
-
- public static void Clear () {
- lock (pool) {
- pool.Clear();
- }
- }
-
- public static int GetSize () {
- return pool.Count;
- }
- }
- }
|