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.
reviewable/pr1063/r24
Tyrone Wu 3 weeks ago
parent 85d67acb79
commit 0bf64aa0d1
No known key found for this signature in database
GPG Key ID: 978B1A1B79210AD6

@ -113,7 +113,9 @@ impl ProgramInfo {
pub fn map_ids(&self) -> Result<Option<Vec<u32>>, ProgramError> { pub fn map_ids(&self) -> Result<Option<Vec<u32>>, ProgramError> {
static CACHE: OnceLock<bool> = OnceLock::new(); static CACHE: OnceLock<bool> = OnceLock::new();
CACHE 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(|| { .then(|| {
let mut map_ids = vec![0u32; self.0.nr_map_ids as usize]; 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)?; 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<bool> { pub fn gpl_compatible(&self) -> Option<bool> {
static CACHE: OnceLock<bool> = OnceLock::new(); static CACHE: OnceLock<bool> = OnceLock::new();
CACHE 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) .then_some(self.0.gpl_compatible() != 0)
} }

Loading…
Cancel
Save