Skip to content

Commit

Permalink
Speed up comment finding
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Oct 15, 2024
1 parent f842df1 commit d811e79
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
/// Find the location where a comment begins in a line
pub fn find_comment_index(line: &str) -> Option<usize> {
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
}
Expand Down

0 comments on commit d811e79

Please sign in to comment.