From d811e79c160bebc3080bb3fe0eb53e2a3d703d5f Mon Sep 17 00:00:00 2001 From: William G Underwood <42812654+WGUNDERWOOD@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:36:15 +0100 Subject: [PATCH] Speed up comment finding --- src/comments.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/comments.rs b/src/comments.rs index f5658ad..65a778c 100644 --- a/src/comments.rs +++ b/src/comments.rs @@ -2,12 +2,15 @@ /// Find the location where a comment begins in a line pub fn find_comment_index(line: &str) -> Option { - let mut prev_c = ' '; - for (i, c) in line.char_indices() { - if c == '%' && prev_c != '\\' { - return Some(i); + // often there is no '%' so check this first + if line.contains('%') { + let mut prev_c = ' '; + for (i, c) in line.char_indices() { + if c == '%' && prev_c != '\\' { + return Some(i); + } + prev_c = c; } - prev_c = c; } None }