From ad6432c8ef9e27a37bdb440f8deba0e3e36a58f8 Mon Sep 17 00:00:00 2001 From: klensy Date: Tue, 23 Jan 2024 11:12:24 +0300 Subject: [PATCH] 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 --- src/tools/compiletest/src/runtest.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8be4def15de..ca7efea07ca 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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 = Lazy::new(|| { Regex::new(r"╾─*a(lloc)?([0-9]+)(\+0x[0-9]+)?()?( \([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 = + 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);