From d790ea7d533c3c48b09a2f16f3fef549aa96be78 Mon Sep 17 00:00:00 2001 From: Yiyu Lin Date: Thu, 13 Apr 2023 09:08:01 +0800 Subject: refactor(cli,ext,ops): cleanup `regex` with `lazy-regex` (#17296) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - bump deps: the newest `lazy-regex` need newer `oncecell` and `regex` - reduce `unwrap` - remove dep `lazy_static` - make more regex cached --------- Co-authored-by: Bartek IwaƄczuk --- cli/tools/test.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'cli/tools/test.rs') diff --git a/cli/tools/test.rs b/cli/tools/test.rs index ce99a6edc..7d6a6baa4 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -1031,8 +1031,8 @@ fn extract_files_from_source_comments( scope_analysis: false, })?; let comments = parsed_source.comments().get_vec(); - let blocks_regex = Regex::new(r"```([^\r\n]*)\r?\n([\S\s]*?)```")?; - let lines_regex = Regex::new(r"(?:\* ?)(?:\# ?)?(.*)")?; + let blocks_regex = lazy_regex::regex!(r"```([^\r\n]*)\r?\n([\S\s]*?)```"); + let lines_regex = lazy_regex::regex!(r"(?:\* ?)(?:\# ?)?(.*)"); let files = comments .iter() @@ -1049,8 +1049,8 @@ fn extract_files_from_source_comments( &comment.text, media_type, parsed_source.text_info().line_index(comment.start()), - &blocks_regex, - &lines_regex, + blocks_regex, + lines_regex, ) }) .flatten() @@ -1069,16 +1069,16 @@ fn extract_files_from_fenced_blocks( // check can be done to see if a block is inside a comment (and skip typechecking) // or not by checking for the presence of capturing groups in the matches. let blocks_regex = - Regex::new(r"(?s)|```([^\r\n]*)\r?\n([\S\s]*?)```")?; - let lines_regex = Regex::new(r"(?:\# ?)?(.*)")?; + lazy_regex::regex!(r"(?s)|```([^\r\n]*)\r?\n([\S\s]*?)```"); + let lines_regex = lazy_regex::regex!(r"(?:\# ?)?(.*)"); extract_files_from_regex_blocks( specifier, source, media_type, /* file line index */ 0, - &blocks_regex, - &lines_regex, + blocks_regex, + lines_regex, ) } -- cgit v1.2.3