From c52597c806ca1835bc706ba8b77d11cffd861465 Mon Sep 17 00:00:00 2001 From: Aaronepower Date: Tue, 16 Aug 2016 00:29:52 +0100 Subject: [PATCH] version bump, speed increase --- Cargo.lock | 2 +- Cargo.toml | 2 +- cli.yml | 2 +- src/lib/utils/fs.rs | 62 +++++++++++++++++---------------------------- 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e6876cb..0f8a11b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "tokei" -version = "4.0.0" +version = "4.1.0" dependencies = [ "clap 2.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index d952e3a..cbed078 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT/Apache-2.0" name = "tokei" readme = "README.md" repository = "https://github.com/Aaronepower/tokei.git" -version = "4.1.0" +version = "4.1.1" [[bin]] doc = false diff --git a/cli.yml b/cli.yml index a530b7e..98b042a 100644 --- a/cli.yml +++ b/cli.yml @@ -5,7 +5,7 @@ about: Count Code, Quickly. author: Aaron P. bin_name: Tokei name: Tokei -version: 4.1.0 +version: 4.1.1 args: - exclude: help: Ignore all files & directories containing the word. diff --git a/src/lib/utils/fs.rs b/src/lib/utils/fs.rs index 192b647..ca35565 100644 --- a/src/lib/utils/fs.rs +++ b/src/lib/utils/fs.rs @@ -20,54 +20,38 @@ pub fn has_trailing_comments(line: &str, comment_end: &'static str, nested: bool) -> bool { - let mut is_in_comments: u8 = 0; + let mut is_in_comments = 0u64; - if let Some(start) = line.find(comment) { - if let Some(end) = line.rfind(comment_end) { + let start = match line.find(comment) { + Some(start) => start, + None => return false, + }; - let section = &line[start..end + comment_end.len()]; - - let length = if comment.len() > comment_end.len() { - comment.len() + let end = match line.rfind(comment_end) { + Some(end) => end, + None => return true, + }; + + let mut chars = line[start..end + comment_end.len()].chars(); + loop { + let window = chars.as_str(); + + if window.starts_with(comment) { + if nested { + is_in_comments += 1; } else { - comment_end.len() - }; - - let vec = section.chars().collect::>(); - - for chars in vec.windows(length) { - let window = { - let mut window = String::new(); - for ch in chars { - window.push(*ch); - } - window - }; - - if window.contains(comment) { - if nested { - is_in_comments += 1; - } else { - is_in_comments = 1; - } - continue; - } else if window.contains(comment_end) { - if nested && is_in_comments != 0 { - is_in_comments -= 1; - } else { - is_in_comments = 0; - } - continue; - } + is_in_comments = 1; } + } else if window.starts_with(comment_end) { + is_in_comments = is_in_comments.saturating_sub(1); + } - } else { - is_in_comments = 1; + if chars.next().is_none() { + break; } } is_in_comments != 0 - } pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,