Skip to content

Commit c10a52e

Browse files
committed
tidy: wrap regexes with lazy_static
yes, once_cell better, but ... this reduces from ==31349== Total: 1,365,199,543 bytes in 4,774,213 blocks ==31349== At t-gmax: 10,975,708 bytes in 66,093 blocks ==31349== At t-end: 2,880,947 bytes in 12,332 blocks ==31349== Reads: 5,210,008,956 bytes ==31349== Writes: 1,280,920,127 bytes to ==47796== Total: 821,467,407 bytes in 3,955,595 blocks ==47796== At t-gmax: 10,976,209 bytes in 66,100 blocks ==47796== At t-end: 2,944,016 bytes in 12,490 blocks ==47796== Reads: 4,788,959,023 bytes ==47796== Writes: 975,493,639 bytes miropt-test-tools: remove regex usage this removes regex usage and slightly refactors ext stripping in one case
1 parent c401f09 commit c10a52e

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -2490,9 +2490,6 @@ dependencies = [
24902490
[[package]]
24912491
name = "miropt-test-tools"
24922492
version = "0.1.0"
2493-
dependencies = [
2494-
"regex",
2495-
]
24962493

24972494
[[package]]
24982495
name = "native-tls"

src/tools/miropt-test-tools/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
regex = "1.0"

src/tools/miropt-test-tools/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,19 @@ pub fn files_for_miropt_test(
100100
} else {
101101
// Allow-list for file extensions that can be produced by MIR dumps.
102102
// Other extensions can be added here, as needed by new dump flags.
103-
let ext_re = regex::Regex::new(r#"(\.(mir|dot))$"#).unwrap();
104-
let cap = ext_re.captures_iter(test_name).next().unwrap_or_else(|| {
105-
panic!("in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}")
106-
});
107-
let extension = cap.get(1).unwrap().as_str();
103+
static ALLOWED_EXT: &[&str] = &["mir", "dot"];
104+
let Some((test_name_wo_ext, test_name_ext)) = test_name.rsplit_once('.') else {
105+
panic!(
106+
"in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}"
107+
)
108+
};
109+
if !ALLOWED_EXT.contains(&test_name_ext) {
110+
panic!(
111+
"in {testfile:?}:\nEMIT_MIR has an unrecognized extension: {test_name}, expected one of {ALLOWED_EXT:?}"
112+
)
113+
}
108114

109-
expected_file =
110-
format!("{}{}{}", test_name.trim_end_matches(extension), suffix, extension,);
115+
expected_file = format!("{}{}.{}", test_name_wo_ext, suffix, test_name_ext);
111116
from_file = test_name.to_string();
112117
assert!(test_names.next().is_none(), "two mir pass names specified for MIR dump");
113118
to_file = None;

src/tools/tidy/src/style.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ fn should_ignore(line: &str) -> bool {
127127
// Matches test annotations like `//~ ERROR text`.
128128
// This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
129129
// update both if either are changed.
130-
let re = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
131-
re.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
130+
lazy_static::lazy_static! {
131+
static ref ANNOTATION_RE: Regex = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
132+
}
133+
ANNOTATION_RE.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
132134
}
133135

134136
/// Returns `true` if `line` is allowed to be longer than the normal limit.

0 commit comments

Comments
 (0)