From: Luciano Bestia Date: Fri, 5 Feb 2021 13:32:03 +0000 (+0100) Subject: simple comparison instead of regex X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=084b21bc36cd624e8db708eb1e12dd6db99a0602;p=rust.git simple comparison instead of regex --- diff --git a/Cargo.lock b/Cargo.lock index 674c75450b8..30cef4cf81d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,15 +15,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" -[[package]] -name = "aho-corasick" -version = "0.7.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" -dependencies = [ - "memchr", -] - [[package]] name = "ansi_term" version = "0.12.1" @@ -649,13 +640,11 @@ dependencies = [ "ide_db", "indexmap", "itertools 0.10.0", - "lazy_static", "log", "oorandom", "profile", "pulldown-cmark", "pulldown-cmark-to-cmark", - "regex", "rustc-hash", "ssr", "stdx", @@ -1317,10 +1306,7 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ - "aho-corasick", - "memchr", "regex-syntax", - "thread_local", ] [[package]] diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml index 6ec1064267e..15a48c0f37b 100644 --- a/crates/ide/Cargo.toml +++ b/crates/ide/Cargo.toml @@ -31,13 +31,10 @@ assists = { path = "../assists", version = "0.0.0" } ssr = { path = "../ssr", version = "0.0.0" } completion = { path = "../completion", version = "0.0.0" } -lazy_static = "1.4.0" -regex = "1.4.3" -env_logger = { version = "0.8.1", default-features = false } - # ide should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. hir = { path = "../hir", version = "0.0.0" } [dev-dependencies] expect-test = "1.1" +env_logger = { version = "0.8.1", default-features = false } \ No newline at end of file diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 99f0c3c99af..7ba775a771c 100644 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -9,8 +9,6 @@ SyntaxNode, TextRange, TextSize, }; -use lazy_static::lazy_static; - #[derive(Debug, PartialEq, Eq)] pub enum FoldKind { Comment, @@ -53,17 +51,10 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { // Fold groups of comments if let Some(comment) = ast::Comment::cast(token) { if !visited_comments.contains(&comment) { - // regions are not really comments - use regex::Regex; - lazy_static! { - static ref RE_START: Regex = - Regex::new(r"^\s*//\s*#?region\b").unwrap(); - static ref RE_END: Regex = - Regex::new(r"^\s*//\s*#?endregion\b").unwrap(); - } - if RE_START.is_match(comment.text()) { + // regions are not real comments + if comment.text().trim().starts_with("// region:") { regions_starts.push(comment.syntax().text_range().start()); - } else if RE_END.is_match(comment.text()) { + } else if comment.text().trim().starts_with("// endregion") { if !regions_starts.is_empty() { res.push(Fold { range: TextRange::new( @@ -202,15 +193,10 @@ fn contiguous_range_for_comment( } if let Some(c) = ast::Comment::cast(token) { if c.kind() == group_kind { - // regions are not really comments - use regex::Regex; - lazy_static! { - static ref RE_START: Regex = - Regex::new(r"^\s*//\s*#?region\b").unwrap(); - static ref RE_END: Regex = - Regex::new(r"^\s*//\s*#?endregion\b").unwrap(); - } - if RE_START.is_match(c.text()) || RE_END.is_match(c.text()) { + // regions are not real comments + if c.text().trim().starts_with("// region:") + || c.text().trim().starts_with("// endregion") + { break; } else { visited.insert(c.clone());