forked from sarbian/ModuleManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBuilderPool.cs
More file actions
33 lines (28 loc) · 857 Bytes
/
Copy pathStringBuilderPool.cs
File metadata and controls
33 lines (28 loc) · 857 Bytes
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
using System;
using System.Text;
namespace ModuleManager.Utils
{
public static class StringBuilderPool
{
[System.ThreadStatic]
private static StringBuilder cachedBuilder;
public static StringBuilder Rent(int capacity = 0)
{
StringBuilder builder = cachedBuilder;
if (builder == null)
return capacity > 0 ? new StringBuilder(capacity) : new StringBuilder();
cachedBuilder = null;
builder.Clear();
if (capacity > 0 && builder.Capacity < capacity)
builder.Capacity = capacity;
return builder;
}
public static void Return(StringBuilder builder)
{
if (builder == null)
return;
builder.Clear();
cachedBuilder = builder;
}
}
}