Skip to content

Commit 37a196a

Browse files
authored
Pool commentState allocations (#1286)
1 parent b594699 commit 37a196a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

internal/printer/printer.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ type Printer struct {
136136
inExtends bool // whether we are emitting the `extends` clause of a ConditionalType or InferType
137137
nameGenerator NameGenerator
138138
makeFileLevelOptimisticUniqueName func(string) string
139+
commentStatePool core.Pool[commentState]
139140
}
140141

141142
type detachedCommentsInfo struct {
@@ -4993,7 +4994,9 @@ func (p *Printer) emitCommentsBeforeNode(node *ast.Node) *commentState {
49934994
p.commentsDisabled = true
49944995
}
49954996

4996-
return &commentState{emitFlags, commentRange, containerPos, containerEnd, declarationListContainerEnd}
4997+
c := p.commentStatePool.New()
4998+
*c = commentState{emitFlags, commentRange, containerPos, containerEnd, declarationListContainerEnd}
4999+
return c
49975000
}
49985001

49995002
func (p *Printer) emitCommentsAfterNode(node *ast.Node, state *commentState) {
@@ -5046,7 +5049,7 @@ func (p *Printer) emitCommentsBeforeToken(token ast.Kind, pos int, contextNode *
50465049
p.decreaseIndentIf(needsIndent)
50475050
}
50485051

5049-
return &commentState{}, pos
5052+
return p.commentStatePool.New(), pos
50505053
}
50515054

50525055
func (p *Printer) emitCommentsAfterToken(token ast.Kind, pos int, contextNode *ast.Node, state *commentState) {

0 commit comments

Comments
 (0)