Skip to content

Commit ad6432c

Browse files
committed
compiletest: reduce useless regex rebuilds
before: ==8812== Total: 2,374,977,159 bytes in 6,840,026 blocks ==8812== At t-gmax: 8,090,486 bytes in 3,389 blocks ==8812== At t-end: 3,185,454 bytes in 757 blocks ==8812== Reads: 1,873,472,286 bytes ==8812== Writes: 1,249,411,589 bytes ==11212== I refs: 6,370,244,180 after: ==18725== Total: 429,769,246 bytes in 957,259 blocks ==18725== At t-gmax: 8,058,316 bytes in 3,502 blocks ==18725== At t-end: 3,045,261 bytes in 1,097 blocks ==18725== Reads: 431,872,599 bytes ==18725== Writes: 214,738,653 bytes ==20839== I refs: 1,873,010,089
1 parent 6745c60 commit ad6432c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/tools/compiletest/src/runtest.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -4315,10 +4315,11 @@ impl<'test> TestCx<'test> {
43154315
let mut seen_allocs = indexmap::IndexSet::new();
43164316

43174317
// The alloc-id appears in pretty-printed allocations.
4318-
let re =
4318+
static ALLOC_ID_PP_RE: Lazy<Regex> = Lazy::new(|| {
43194319
Regex::new(r"╾─*a(lloc)?([0-9]+)(\+0x[0-9]+)?(<imm>)?( \([0-9]+ ptr bytes\))?─*╼")
4320-
.unwrap();
4321-
normalized = re
4320+
.unwrap()
4321+
});
4322+
normalized = ALLOC_ID_PP_RE
43224323
.replace_all(&normalized, |caps: &Captures<'_>| {
43234324
// Renumber the captured index.
43244325
let index = caps.get(2).unwrap().as_str().to_string();
@@ -4331,8 +4332,9 @@ impl<'test> TestCx<'test> {
43314332
.into_owned();
43324333

43334334
// The alloc-id appears in a sentence.
4334-
let re = Regex::new(r"\balloc([0-9]+)\b").unwrap();
4335-
normalized = re
4335+
static ALLOC_ID_RE: Lazy<Regex> =
4336+
Lazy::new(|| Regex::new(r"\balloc([0-9]+)\b").unwrap());
4337+
normalized = ALLOC_ID_RE
43364338
.replace_all(&normalized, |caps: &Captures<'_>| {
43374339
let index = caps.get(1).unwrap().as_str().to_string();
43384340
let (index, _) = seen_allocs.insert_full(index);

0 commit comments

Comments
 (0)