From 6060ee5e201c7f3431144509b78f2f3db3cb2625 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sun, 29 Mar 2026 23:01:23 -0300 Subject: [PATCH] computing `lastPrintableIndex` only once instead of checking in every loop --- src/slang-printers/print-comments.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/slang-printers/print-comments.ts b/src/slang-printers/print-comments.ts index f011d7d2e..d7cb0f1f2 100644 --- a/src/slang-printers/print-comments.ts +++ b/src/slang-printers/print-comments.ts @@ -22,19 +22,18 @@ export function printComments( options: ParserOptions ): Doc[] { if (node.comments === undefined) return []; + const lastPrintableIndex = node.comments.findLastIndex(isPrintable); return joinExisting( line, - path.map(({ node: comment }, index, comments: Comment[]) => { + path.map(({ node: comment }, index) => { if (!isPrintable(comment)) { return ''; } comment.printed = true; - const isLast = - index === comments.length - 1 || - comments.slice(index + 1).findIndex(isPrintable) === -1; return [ printComment(path), - !isLast && util.isNextLineEmpty(options.originalText, locEnd(comment)) + index !== lastPrintableIndex && + util.isNextLineEmpty(options.originalText, locEnd(comment)) ? hardline : '' ];