From b8801dc445bd2ca808ebe6049593eb701d7baa5a Mon Sep 17 00:00:00 2001 From: Tyrone Wu Date: Fri, 28 Mar 2025 22:03:48 +0000 Subject: [PATCH] aya: short-circuit info field if non-zero Short-circuits `CACHE` to true if the field is non-zero. This saves from executing the probing logic since the logic essentially checks if the field can process (or doesn't error) non-zero value. --- aya/src/programs/info.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aya/src/programs/info.rs b/aya/src/programs/info.rs index 753d6054..ef6b5378 100644 --- a/aya/src/programs/info.rs +++ b/aya/src/programs/info.rs @@ -113,7 +113,9 @@ impl ProgramInfo { pub fn map_ids(&self) -> Result>, ProgramError> { static CACHE: OnceLock = OnceLock::new(); CACHE - .get_or_init(|| matches!(is_prog_info_map_ids_supported(), Ok(true))) + .get_or_init(|| { + self.0.nr_map_ids > 0 || matches!(is_prog_info_map_ids_supported(), Ok(true)) + }) .then(|| { let mut map_ids = vec![0u32; self.0.nr_map_ids as usize]; bpf_prog_get_info_by_fd(self.fd()?.as_fd(), &mut map_ids)?; @@ -147,7 +149,9 @@ impl ProgramInfo { pub fn gpl_compatible(&self) -> Option { static CACHE: OnceLock = OnceLock::new(); CACHE - .get_or_init(|| matches!(is_prog_info_license_supported(), Ok(true))) + .get_or_init(|| { + self.0.gpl_compatible() != 0 || matches!(is_prog_info_license_supported(), Ok(true)) + }) .then_some(self.0.gpl_compatible() != 0) }