-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser_pool.go
More file actions
37 lines (32 loc) · 754 Bytes
/
Copy pathparser_pool.go
File metadata and controls
37 lines (32 loc) · 754 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
package goeval
import "sync"
var parserPool = sync.Pool{
New: func() any {
return new(yyParserImpl)
},
}
func parseWithPool(lex yyLexer) int {
parser := parserPool.Get().(*yyParserImpl)
defer func() {
parser.lval = yySymType{}
parser.stack = [yyInitialStackSize]yySymType{}
parser.char = 0
parserPool.Put(parser)
}()
return parser.Parse(lex)
}
var compileParserPool = sync.Pool{
New: func() any {
return new(compileParserImpl)
},
}
func compileParseWithPool(lex compileLexer) int {
parser := compileParserPool.Get().(*compileParserImpl)
defer func() {
parser.lval = compileSymType{}
parser.stack = [compileInitialStackSize]compileSymType{}
parser.char = 0
compileParserPool.Put(parser)
}()
return parser.Parse(lex)
}