mirror of
https://gitee.com/cssfw/EasyTools.git
synced 2026-03-28 12:01:36 +08:00
default
This commit is contained in:
9
Utils/Pool/IPool.cs
Normal file
9
Utils/Pool/IPool.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace EasyTools.Utils.Pool
|
||||
{
|
||||
public interface IPool<T>
|
||||
{
|
||||
public T Get();
|
||||
|
||||
public void Return(T obj);
|
||||
}
|
||||
}
|
||||
29
Utils/Pool/StringBuilderPool.cs
Normal file
29
Utils/Pool/StringBuilderPool.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Text;
|
||||
using BasePools = NorthwoodLib.Pools;
|
||||
|
||||
namespace EasyTools.Utils.Pool
|
||||
{
|
||||
public class StringBuilderPool : IPool<StringBuilder>
|
||||
{
|
||||
private StringBuilderPool()
|
||||
{
|
||||
}
|
||||
|
||||
public static StringBuilderPool Pool { get; } = new();
|
||||
|
||||
public StringBuilder Get() => BasePools.StringBuilderPool.Shared.Rent();
|
||||
|
||||
public StringBuilder Get(int capacity) => BasePools.StringBuilderPool.Shared.Rent(capacity);
|
||||
|
||||
public void Return(StringBuilder obj) => BasePools.StringBuilderPool.Shared.Return(obj);
|
||||
|
||||
public string ToStringReturn(StringBuilder obj)
|
||||
{
|
||||
string s = obj.ToString();
|
||||
|
||||
Return(obj);
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user