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
This commit is contained in:
klensy 2024-01-23 11:12:24 +03:00
parent 6745c6000a
commit ad6432c8ef

View File

@ -4315,10 +4315,11 @@ impl<'test> TestCx<'test> {
let mut seen_allocs = indexmap::IndexSet::new();
// The alloc-id appears in pretty-printed allocations.
let re =
static ALLOC_ID_PP_RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"╾─*a(lloc)?([0-9]+)(\+0x[0-9]+)?(<imm>)?( \([0-9]+ ptr bytes\))?─*╼")
.unwrap();
normalized = re
.unwrap()
});
normalized = ALLOC_ID_PP_RE
.replace_all(&normalized, |caps: &Captures<'_>| {
// Renumber the captured index.
let index = caps.get(2).unwrap().as_str().to_string();
@ -4331,8 +4332,9 @@ impl<'test> TestCx<'test> {
.into_owned();
// The alloc-id appears in a sentence.
let re = Regex::new(r"\balloc([0-9]+)\b").unwrap();
normalized = re
static ALLOC_ID_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\balloc([0-9]+)\b").unwrap());
normalized = ALLOC_ID_RE
.replace_all(&normalized, |caps: &Captures<'_>| {
let index = caps.get(1).unwrap().as_str().to_string();
let (index, _) = seen_allocs.insert_full(index);