Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PooledStringBuilder.cs
Go to the documentation of this file.
1using System.Text;
2
4
5internal sealed class PooledStringBuilder
6{
7 public readonly StringBuilder Builder = new StringBuilder();
8
10
12
13 public int Length => Builder.Length;
14
16 {
17 _pool = pool;
18 }
19
20 public void Free()
21 {
22 StringBuilder builder = Builder;
23 if (builder.Capacity <= 1024)
24 {
25 builder.Clear();
26 _pool.Free(this);
27 }
28 }
29
30 public string ToStringAndFree()
31 {
32 string result = Builder.ToString();
33 Free();
34 return result;
35 }
36
38 {
40 pool = new ObjectPool<PooledStringBuilder>(() => new PooledStringBuilder(pool), 32);
41 return pool;
42 }
43
45 {
46 return s_poolInstance.Allocate();
47 }
48}
static ObjectPool< PooledStringBuilder > CreatePool()
static readonly ObjectPool< PooledStringBuilder > s_poolInstance
PooledStringBuilder(ObjectPool< PooledStringBuilder > pool)
readonly ObjectPool< PooledStringBuilder > _pool
override string ToString()