-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pool.cs
80 lines (68 loc) · 2.21 KB
/
Pool.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.Generic;
using System.Text;
// THis file comes from ExCSS almost unmodified
namespace SkiaSharpOpenGLBenchmark
{
internal static class Pool
{
private static readonly Stack<StringBuilder> Builder = new Stack<StringBuilder>();
//private static readonly Stack<SelectorConstructor> Selector = new();
//private static readonly Stack<ValueBuilder> Value = new();
private static readonly object Lock = new object();
public static StringBuilder NewStringBuilder()
{
lock (Lock)
{
return Builder.Count == 0 ? new StringBuilder(1024) : Builder.Pop().Clear();
}
}
/*
public static SelectorConstructor NewSelectorConstructor(AttributeSelectorFactory attributeSelector,
PseudoClassSelectorFactory pseudoClassSelector, PseudoElementSelectorFactory pseudoElementSelector)
{
lock (Lock)
{
return Selector.Count == 0
? new SelectorConstructor(attributeSelector, pseudoClassSelector, pseudoElementSelector)
: Selector.Pop().Reset(attributeSelector, pseudoClassSelector, pseudoElementSelector);
}
}
public static ValueBuilder NewValueBuilder()
{
lock (Lock)
{
return Value.Count == 0
? new ValueBuilder()
: Value.Pop().Reset();
}
}*/
public static string ToPool(this StringBuilder sb)
{
var result = sb.ToString();
lock (Lock)
{
Builder.Push(sb);
}
return result;
}
/*
public static ISelector ToPool(this SelectorConstructor ctor)
{
var result = ctor.GetResult();
lock (Lock)
{
Selector.Push(ctor);
}
return result;
}
public static TokenValue ToPool(this ValueBuilder vb)
{
var result = vb.GetResult();
lock (Lock)
{
Value.Push(vb);
}
return result;
}*/
}
}