-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathStringBuilderCache.cs
More file actions
43 lines (38 loc) · 943 Bytes
/
StringBuilderCache.cs
File metadata and controls
43 lines (38 loc) · 943 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
34
35
36
37
38
39
40
41
42
43
// Copyright (c) Mondol. All rights reserved.
//
// Author: frank
// Email: frank@mondol.info
// Created: 2017-04-16
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mondol
{
public static class StringBuilderCache
{
[ThreadStatic]
private static StringBuilder _cache;
public static StringBuilder Allocate()
{
var sb = _cache;
if (sb == null)
return new StringBuilder();
sb.Length = 0;
_cache = null;
return sb;
}
public static void Free(StringBuilder sb)
{
_cache = sb;
}
public static string ReturnAndFree(StringBuilder sb)
{
var str = sb.ToString();
_cache = sb;
return str;
}
}
}