Skip to content

Commit 638ced5

Browse files
authored
computing lastPrintableIndex only once instead of checking in every loop (#1486)
1 parent dd56f15 commit 638ced5

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/slang-printers/print-comments.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ export function printComments(
2222
options: ParserOptions<AstNode>
2323
): Doc[] {
2424
if (node.comments === undefined) return [];
25+
const lastPrintableIndex = node.comments.findLastIndex(isPrintable);
2526
return joinExisting(
2627
line,
27-
path.map(({ node: comment }, index, comments: Comment[]) => {
28+
path.map(({ node: comment }, index) => {
2829
if (!isPrintable(comment)) {
2930
return '';
3031
}
3132
comment.printed = true;
32-
const isLast =
33-
index === comments.length - 1 ||
34-
comments.slice(index + 1).findIndex(isPrintable) === -1;
3533
return [
3634
printComment(path),
37-
!isLast && util.isNextLineEmpty(options.originalText, locEnd(comment))
35+
index !== lastPrintableIndex &&
36+
util.isNextLineEmpty(options.originalText, locEnd(comment))
3837
? hardline
3938
: ''
4039
];

0 commit comments

Comments
 (0)