-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStackPool{T}.cs
54 lines (43 loc) · 1.17 KB
/
StackPool{T}.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections.Generic;
namespace System.Collections.Pooling
{
public static class StackPool<T>
{
private static readonly Pool<Stack<T>> _pool = new Pool<Stack<T>>();
public static Stack<T> Get()
=> _pool.Get();
public static void Return(Stack<T> item)
{
if (item == null)
return;
item.Clear();
_pool.Return(item);
}
public static void Return(params Stack<T>[] items)
{
if (items == null)
return;
foreach (var item in items)
{
if (item == null)
continue;
item.Clear();
_pool.Return(item);
}
}
public static void Return(IEnumerable<Stack<T>> items)
{
if (items == null)
return;
foreach (var item in items)
{
if (item == null)
continue;
item.Clear();
_pool.Return(item);
}
}
public static void Clear()
=> _pool.Clear();
}
}