-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_pool_extensions.go
300 lines (265 loc) · 6.85 KB
/
node_pool_extensions.go
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package twig
import (
"sync"
)
// This file extends the node pool system to cover all node types,
// following the implementation strategy in the zero-allocation plan.
// BlockNodePool provides a pool for BlockNode objects
var BlockNodePool = sync.Pool{
New: func() interface{} {
return &BlockNode{}
},
}
// GetBlockNode gets a BlockNode from the pool and initializes it
func GetBlockNode(name string, body []Node, line int) *BlockNode {
node := BlockNodePool.Get().(*BlockNode)
node.name = name
node.body = body
node.line = line
return node
}
// ReleaseBlockNode returns a BlockNode to the pool
func ReleaseBlockNode(node *BlockNode) {
if node == nil {
return
}
node.name = ""
node.body = nil
BlockNodePool.Put(node)
}
// ExtendsNodePool provides a pool for ExtendsNode objects
var ExtendsNodePool = sync.Pool{
New: func() interface{} {
return &ExtendsNode{}
},
}
// GetExtendsNode gets an ExtendsNode from the pool and initializes it
func GetExtendsNode(parent Node, line int) *ExtendsNode {
node := ExtendsNodePool.Get().(*ExtendsNode)
node.parent = parent
node.line = line
return node
}
// ReleaseExtendsNode returns an ExtendsNode to the pool
func ReleaseExtendsNode(node *ExtendsNode) {
if node == nil {
return
}
node.parent = nil
ExtendsNodePool.Put(node)
}
// IncludeNodePool provides a pool for IncludeNode objects
var IncludeNodePool = sync.Pool{
New: func() interface{} {
return &IncludeNode{}
},
}
// GetIncludeNode gets an IncludeNode from the pool and initializes it
func GetIncludeNode(template Node, variables map[string]Node, ignoreMissing, only, sandboxed bool, line int) *IncludeNode {
node := IncludeNodePool.Get().(*IncludeNode)
node.template = template
node.variables = variables
node.ignoreMissing = ignoreMissing
node.only = only
node.sandboxed = sandboxed
node.line = line
return node
}
// ReleaseIncludeNode returns an IncludeNode to the pool
func ReleaseIncludeNode(node *IncludeNode) {
if node == nil {
return
}
node.template = nil
node.variables = nil
node.ignoreMissing = false
node.only = false
node.sandboxed = false
IncludeNodePool.Put(node)
}
// SetNodePool provides a pool for SetNode objects
var SetNodePool = sync.Pool{
New: func() interface{} {
return &SetNode{}
},
}
// GetSetNode gets a SetNode from the pool and initializes it
func GetSetNode(name string, value Node, line int) *SetNode {
node := SetNodePool.Get().(*SetNode)
node.name = name
node.value = value
node.line = line
return node
}
// ReleaseSetNode returns a SetNode to the pool
func ReleaseSetNode(node *SetNode) {
if node == nil {
return
}
node.name = ""
node.value = nil
SetNodePool.Put(node)
}
// CommentNodePool provides a pool for CommentNode objects
var CommentNodePool = sync.Pool{
New: func() interface{} {
return &CommentNode{}
},
}
// GetCommentNode gets a CommentNode from the pool and initializes it
func GetCommentNode(content string, line int) *CommentNode {
node := CommentNodePool.Get().(*CommentNode)
node.content = content
node.line = line
return node
}
// ReleaseCommentNode returns a CommentNode to the pool
func ReleaseCommentNode(node *CommentNode) {
if node == nil {
return
}
node.content = ""
CommentNodePool.Put(node)
}
// MacroNodePool provides a pool for MacroNode objects
var MacroNodePool = sync.Pool{
New: func() interface{} {
return &MacroNode{}
},
}
// GetMacroNode gets a MacroNode from the pool and initializes it
func GetMacroNode(name string, params []string, defaults map[string]Node, body []Node, line int) *MacroNode {
node := MacroNodePool.Get().(*MacroNode)
node.name = name
node.params = params
node.defaults = defaults
node.body = body
node.line = line
return node
}
// ReleaseMacroNode returns a MacroNode to the pool
func ReleaseMacroNode(node *MacroNode) {
if node == nil {
return
}
node.name = ""
node.params = nil
node.defaults = nil
node.body = nil
MacroNodePool.Put(node)
}
// ImportNodePool provides a pool for ImportNode objects
var ImportNodePool = sync.Pool{
New: func() interface{} {
return &ImportNode{}
},
}
// GetImportNode gets an ImportNode from the pool and initializes it
func GetImportNode(template Node, module string, line int) *ImportNode {
node := ImportNodePool.Get().(*ImportNode)
node.template = template
node.module = module
node.line = line
return node
}
// ReleaseImportNode returns an ImportNode to the pool
func ReleaseImportNode(node *ImportNode) {
if node == nil {
return
}
node.template = nil
node.module = ""
ImportNodePool.Put(node)
}
// FromImportNodePool provides a pool for FromImportNode objects
var FromImportNodePool = sync.Pool{
New: func() interface{} {
return &FromImportNode{}
},
}
// GetFromImportNode gets a FromImportNode from the pool and initializes it
func GetFromImportNode(template Node, macros []string, aliases map[string]string, line int) *FromImportNode {
node := FromImportNodePool.Get().(*FromImportNode)
node.template = template
node.macros = macros
node.aliases = aliases
node.line = line
return node
}
// ReleaseFromImportNode returns a FromImportNode to the pool
func ReleaseFromImportNode(node *FromImportNode) {
if node == nil {
return
}
node.template = nil
node.macros = nil
node.aliases = nil
FromImportNodePool.Put(node)
}
// VerbatimNodePool provides a pool for VerbatimNode objects
var VerbatimNodePool = sync.Pool{
New: func() interface{} {
return &VerbatimNode{}
},
}
// GetVerbatimNode gets a VerbatimNode from the pool and initializes it
func GetVerbatimNode(content string, line int) *VerbatimNode {
node := VerbatimNodePool.Get().(*VerbatimNode)
node.content = content
node.line = line
return node
}
// ReleaseVerbatimNode returns a VerbatimNode to the pool
func ReleaseVerbatimNode(node *VerbatimNode) {
if node == nil {
return
}
node.content = ""
VerbatimNodePool.Put(node)
}
// DoNodePool provides a pool for DoNode objects
var DoNodePool = sync.Pool{
New: func() interface{} {
return &DoNode{}
},
}
// GetDoNode gets a DoNode from the pool and initializes it
func GetDoNode(expression Node, line int) *DoNode {
node := DoNodePool.Get().(*DoNode)
node.expression = expression
node.line = line
return node
}
// ReleaseDoNode returns a DoNode to the pool
func ReleaseDoNode(node *DoNode) {
if node == nil {
return
}
node.expression = nil
DoNodePool.Put(node)
}
// ApplyNodePool provides a pool for ApplyNode objects
var ApplyNodePool = sync.Pool{
New: func() interface{} {
return &ApplyNode{}
},
}
// GetApplyNode gets an ApplyNode from the pool and initializes it
func GetApplyNode(body []Node, filter string, args []Node, line int) *ApplyNode {
node := ApplyNodePool.Get().(*ApplyNode)
node.body = body
node.filter = filter
node.args = args
node.line = line
return node
}
// ReleaseApplyNode returns an ApplyNode to the pool
func ReleaseApplyNode(node *ApplyNode) {
if node == nil {
return
}
node.body = nil
node.filter = ""
node.args = nil
ApplyNodePool.Put(node)
}