From 6f2a8c8a5c47098fb5e5a75ecebdff493d486c97 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 17 Jul 2023 10:49:15 -0400 Subject: [PATCH] aya: avoid an allocation str::rsplitn(2, c) is a special case that can be expressed as str::rsplit_once(c). --- aya-obj/src/obj.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aya-obj/src/obj.rs b/aya-obj/src/obj.rs index 5ac7d3db..a36eb684 100644 --- a/aya-obj/src/obj.rs +++ b/aya-obj/src/obj.rs @@ -378,12 +378,11 @@ impl FromStr for ProgramSection { // parse the common case, eg "xdp/program_name" or // "sk_skb/stream_verdict/program_name" - let mut parts = section.rsplitn(2, '/').collect::>(); - if parts.len() == 1 { - parts.push(parts[0]); - } - let kind = parts[1]; - let name = parts[0].to_owned(); + let (kind, name) = match section.rsplit_once('/') { + None => (section, section), + Some((kind, name)) => (kind, name), + }; + let name = name.to_owned(); Ok(match kind { "kprobe" => KProbe { name },