Skip to content

Commit

Permalink
don't compile Regex in frequently called function get_rust_item (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhance authored Feb 5, 2024
1 parent efb72d4 commit 2aed333
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/rust_verify/src/verus_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,9 @@ pub(crate) fn get_rust_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Ru
}

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

0 comments on commit 2aed333

Please sign in to comment.