Skip to content

Commit

Permalink
tidy: wrap regexes with lazy_static
Browse files Browse the repository at this point in the history
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
  • Loading branch information
klensy committed Jan 16, 2024
1 parent 533cfde commit b54aa1b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,7 @@ dependencies = [
name = "miropt-test-tools"
version = "0.1.0"
dependencies = [
"lazy_static",
"regex",
]

Expand Down
1 change: 1 addition & 0 deletions src/tools/miropt-test-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
regex = "1.0"
lazy_static = "1"
9 changes: 7 additions & 2 deletions src/tools/miropt-test-tools/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::fs;
use std::path::Path;

use regex::Regex;

pub struct MiroptTestFile {
pub expected_file: std::path::PathBuf,
pub from_file: String,
Expand Down Expand Up @@ -98,8 +100,11 @@ pub fn files_for_miropt_test(
from_file = format!("{}.{}.mir", test_name, first_pass);
to_file = Some(second_file);
} else {
let ext_re = regex::Regex::new(r#"(\.(mir|dot|html))$"#).unwrap();
let cap = ext_re
lazy_static::lazy_static! {
static ref EXT_RE: Regex = Regex::new(r#"(\.(mir|dot|html))$"#).unwrap();
}

let cap = EXT_RE
.captures_iter(test_name)
.next()
.expect("test_name has an invalid extension");
Expand Down
6 changes: 4 additions & 2 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ fn should_ignore(line: &str) -> bool {
// Matches test annotations like `//~ ERROR text`.
// This mirrors the regex in src/tools/compiletest/src/runtest.rs, please
// update both if either are changed.
let re = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
re.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
lazy_static::lazy_static! {
static ref ANNOTATION_RE: Regex = Regex::new("\\s*//(\\[.*\\])?~.*").unwrap();
}
ANNOTATION_RE.is_match(line) || ANNOTATIONS_TO_IGNORE.iter().any(|a| line.contains(a))
}

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

0 comments on commit b54aa1b

Please sign in to comment.