Skip to content

Commit c83b659

Browse files
Remove possible allocation of NodeList by eliminating IfElse. (#808)
1 parent 3685da6 commit c83b659

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

internal/parser/jsdoc.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -502,22 +502,32 @@ loop:
502502
p.nextTokenJSDoc()
503503
}
504504
}
505+
505506
p.jsdocCommentsSpace = comments[:0] // Reuse this slice for further parses
506507
if commentsPos == -1 {
507508
commentsPos = p.scanner.TokenFullStart()
508509
}
510+
509511
trimmedComments := trimEnd(strings.Join(comments, ""))
510512
if len(trimmedComments) > 0 {
511513
jsdocText := p.factory.NewJSDocText(trimmedComments)
512514
p.finishNodeWithEnd(jsdocText, linkEnd, commentsPos)
513515
commentParts = append(commentParts, jsdocText)
514516
}
517+
515518
if len(commentParts) > 0 && len(tags) > 0 && commentsPos == -1 {
516519
panic("having parsed tags implies that the end of the comment span should be set")
517520
}
521+
522+
var tagsNodeList *ast.NodeList
523+
if tagsPos != -1 {
524+
tagsNodeList = p.newNodeList(core.NewTextRange(tagsPos, tagsEnd), tags)
525+
}
526+
518527
jsdocComment := p.factory.NewJSDoc(
519528
p.newNodeList(core.NewTextRange(start, commentsPos), commentParts),
520-
core.IfElse(tagsPos != -1, p.newNodeList(core.NewTextRange(tagsPos, tagsEnd), tags), nil))
529+
tagsNodeList,
530+
)
521531
p.finishNodeWithEnd(jsdocComment, fullStart, end)
522532
return jsdocComment
523533
}

0 commit comments

Comments
 (0)