We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a3aed41 commit 307a077Copy full SHA for 307a077
ansi/parser_sync.go
@@ -0,0 +1,26 @@
1
+package ansi
2
+
3
+import (
4
+ "sync"
5
6
+ "github.com/charmbracelet/x/ansi/parser"
7
+)
8
9
+var parserPool = sync.Pool{
10
+ New: func() any {
11
+ return NewParser(parser.MaxParamsSize, 1024*4) // 4MB data buffer
12
+ },
13
+}
14
15
+// GetParser returns a parser from a sync pool.
16
+func GetParser() *Parser {
17
+ return parserPool.Get().(*Parser)
18
19
20
+// PutParser returns a parser to a sync pool. The parser is reset
21
+// automatically.
22
+func PutParser(p *Parser) {
23
+ p.Reset()
24
+ p.DataLen = 0
25
+ parserPool.Put(p)
26
0 commit comments