Skip to content

Commit 20f6396

Browse files
committed
legacy: strip prefix via strip_prefix to avoid additional bound check
1 parent 011d5bb commit 20f6396

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/legacy.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ pub fn demangle(s: &str) -> Result<(Demangle<'_>, &str), ()> {
5050
// First validate the symbol. If it doesn't look like anything we're
5151
// expecting, we just print it literally. Note that we must handle non-Rust
5252
// symbols because we could have any function in the backtrace.
53-
let inner = if s.starts_with("_ZN") {
54-
&s[3..]
55-
} else if s.starts_with("ZN") {
53+
let inner = if let Some(s) = s.strip_prefix("_ZN") {
54+
s
55+
} else if let Some(s) = s.strip_prefix("ZN") {
5656
// On Windows, dbghelp strips leading underscores, so we accept "ZN...E"
5757
// form too.
58-
&s[2..]
59-
} else if s.starts_with("__ZN") {
58+
s
59+
} else if let Some(s) = s.strip_prefix("__ZN") {
6060
// On OSX, symbols are prefixed with an extra _
61-
&s[4..]
61+
s
6262
} else {
6363
return Err(());
6464
};

0 commit comments

Comments
 (0)