Skip to content

Commit a41c2a4

Browse files
committed
Feat: Add StringBuilderPoolPolicy for object pooling
1 parent 1952e14 commit a41c2a4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ---------------------------------------------------------------------------------------------------------------------
2+
// Imports
3+
// ---------------------------------------------------------------------------------------------------------------------
4+
using Microsoft.Extensions.ObjectPool;
5+
using System.Text;
6+
7+
namespace CodeOfChaos.Extensions.ObjectPool;
8+
// ---------------------------------------------------------------------------------------------------------------------
9+
// Code
10+
// ---------------------------------------------------------------------------------------------------------------------
11+
public class StringBuilderPoolPolicy : IPooledObjectPolicy<StringBuilder> {
12+
public StringBuilder Create() => new();
13+
public bool Return(StringBuilder obj) {
14+
obj.Clear();
15+
return obj.Length == 0;
16+
}
17+
}

0 commit comments

Comments
 (0)