forked from laicasaane/unity-supplements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListPool{T}.cs
54 lines (43 loc) · 1.16 KB
/
ListPool{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 ListPool<T>
{
private static readonly Pool<List<T>> _pool = new Pool<List<T>>();
public static List<T> Get()
=> _pool.Get();
public static void Return(List<T> item)
{
if (item == null)
return;
item.Clear();
_pool.Return(item);
}
public static void Return(params List<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<List<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();
}
}