Skip to content

Commit d242dc0

Browse files
committed
lazylock the regex
1 parent f444cdb commit d242dc0

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

objdiff-core/src/obj/read.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use core::{cmp::Ordering, num::NonZeroU64};
1111
use anyhow::{Context, Result, anyhow, bail, ensure};
1212
use object::{Object as _, ObjectSection as _, ObjectSymbol as _};
1313
use regex::Regex;
14+
use std::sync::LazyLock;
1415

1516
use crate::{
1617
arch::{Arch, RelocationOverride, RelocationOverrideTarget, new_arch},
@@ -65,9 +66,10 @@ fn get_normalized_symbol_name(name: &str) -> Option<String> {
6566
// Match MSVC anonymous class symbol names, ignoring the unique ID.
6667
// e.g. ?CheckContextOr@?A0x24773155@@YA_NPBVDataArray@@@Z
6768
// and: ?CheckContextOr@?A0xddf6240c@@YA_NPBVDataArray@@@Z
68-
let re = Regex::new(r"\?A0x[0-9A-Fa-f]{8}@@").unwrap();
69-
if re.is_match(name) {
70-
Some(re.replace_all(name, format!("?A0x{DUMMY_UNIQUE_MSVC_ID}@@")).to_string())
69+
static RE: LazyLock<Regex> =
70+
LazyLock::new(|| Regex::new(r"\?A0x[0-9A-Fa-f]{8}@@").unwrap());
71+
if RE.is_match(name) {
72+
Some(RE.replace_all(name, format!("?A0x{DUMMY_UNIQUE_MSVC_ID}@@")).to_string())
7173
} else {
7274
None
7375
}

0 commit comments

Comments
 (0)