Skip to content

Pool sourceMapState tool #1320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ type Printer struct {
nameGenerator NameGenerator
makeFileLevelOptimisticUniqueName func(string) string
commentStatePool core.Pool[commentState]
sourceMapStatePool core.Pool[sourceMapState]
}

type detachedCommentsInfo struct {
Expand Down Expand Up @@ -5489,7 +5490,9 @@ func (p *Printer) emitSourceMapsBeforeNode(node *ast.Node) *sourceMapState {
p.sourceMapsDisabled = true
}

return &sourceMapState{emitFlags, loc, false}
state := p.sourceMapStatePool.New()
*state = sourceMapState{emitFlags, loc, false}
return state
}

func (p *Printer) emitSourceMapsAfterNode(node *ast.Node, previousState *sourceMapState) {
Expand Down Expand Up @@ -5527,7 +5530,9 @@ func (p *Printer) emitSourceMapsBeforeToken(token ast.Kind, pos int, contextNode
}
}

return &sourceMapState{emitFlags, loc, hasLoc}
state := p.sourceMapStatePool.New()
*state = sourceMapState{emitFlags, loc, hasLoc}
return state
}

func (p *Printer) emitSourceMapsAfterToken(token ast.Kind, pos int, contextNode *ast.Node, previousState *sourceMapState) {
Expand Down