From a23b0bc3a90fe73563ae935386c9aec2b898db4d Mon Sep 17 00:00:00 2001 From: Nik Revenco Date: Tue, 17 Jun 2025 15:17:40 +0100 Subject: [PATCH] perf: Do not unnecessarily call `commen::get_line_comment_token` Co-authored-by: Michael Davis --- helix-term/src/commands.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 983a9cd8b..c2dfe6d5f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3673,14 +3673,17 @@ fn open(cx: &mut Context, open: Open, comment_continuation: CommentContinuation) let above_next_new_line_num = next_new_line_num.saturating_sub(1); - let continue_comment_token = comment::get_line_comment_token( - &loader, - syntax, - text, - doc_default_tokens, - curr_line_num, - ) - .filter(|_| continue_comments); + let continue_comment_token = continue_comments + .then(|| { + comment::get_line_comment_token( + &loader, + syntax, + text, + doc_default_tokens, + curr_line_num, + ) + }) + .flatten(); // Index to insert newlines after, as well as the char width // to use to compensate for those inserted newlines.