Debian Codegraph @

ansi/parser_sync.go

raw
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 p := NewParser()
12 p.SetParamsSize(parser.MaxParamsSize)
13 p.SetDataSize(1024 * 1024 * 4) // 4MB of data buffer
14 return p
15 },
16 }
17
18 // GetParser returns a parser from a sync pool.
19 func GetParser() *Parser {
20 return parserPool.Get().(*Parser)
21 }
22
23 // PutParser returns a parser to a sync pool. The parser is reset
24 // automatically.
25 func PutParser(p *Parser) {
26 p.Reset()
27 p.dataLen = 0
28 parserPool.Put(p)
29 }