Skip to content

Commit 24cbe6b

Browse files
committedJan 16, 2024
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
1 parent f9c2421 commit 24cbe6b

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed
 

‎Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2493,6 +2493,7 @@ dependencies = [
24932493
name = "miropt-test-tools"
24942494
version = "0.1.0"
24952495
dependencies = [
2496+
"lazy_static",
24962497
"regex",
24972498
]
24982499

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

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

66
[dependencies]
77
regex = "1.0"
8+
lazy_static = "1"

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::fs;
22
use std::path::Path;
33

4+
use regex::Regex;
5+
46
pub struct MiroptTestFile {
57
pub expected_file: std::path::PathBuf,
68
pub from_file: String,
@@ -98,8 +100,11 @@ pub fn files_for_miropt_test(
98100
from_file = format!("{}.{}.mir", test_name, first_pass);
99101
to_file = Some(second_file);
100102
} else {
101-
let ext_re = regex::Regex::new(r#"(\.(mir|dot|html))$"#).unwrap();
102-
let cap = ext_re
103+
lazy_static::lazy_static! {
104+
static ref EXT_RE: Regex = Regex::new(r#"(\.(mir|dot|html))$"#).unwrap();
105+
}
106+
107+
let cap = EXT_RE
103108
.captures_iter(test_name)
104109
.next()
105110
.expect("test_name has an invalid extension");

‎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)