Skip to content

Commit 2aed333

Browse files
authored
don't compile Regex in frequently called function get_rust_item (#971)
1 parent efb72d4 commit 2aed333

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

source/rust_verify/src/verus_items.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ pub(crate) fn get_rust_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Ru
631631
}
632632

633633
if let Some(rust_path) = rust_path {
634-
let num_re = Regex::new(r"^([A-Za-z0-9_]+)::(MIN|MAX|BITS)").unwrap();
634+
static NUM_RE: std::sync::OnceLock<Regex> = std::sync::OnceLock::new();
635+
let num_re =
636+
NUM_RE.get_or_init(|| Regex::new(r"^([A-Za-z0-9_]+)::(MIN|MAX|BITS)").unwrap());
635637
if let Some(captures) = num_re.captures(rust_path) {
636638
let ty_name = captures.get(1).expect("invalid int intrinsic regex");
637639
let const_name = captures.get(2).expect("invalid int intrinsic regex");

0 commit comments

Comments
 (0)