-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHashSetPool{T}.cs
54 lines (43 loc) · 1.18 KB
/
HashSetPool{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 HashSetPool<T>
{
private static readonly Pool<HashSet<T>> _pool = new Pool<HashSet<T>>();
public static HashSet<T> Get()
=> _pool.Get();
public static void Return(HashSet<T> item)
{
if (item == null)
return;
item.Clear();
_pool.Return(item);
}
public static void Return(params HashSet<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<HashSet<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();
}
}