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/r28
Tyrone Wu 3 weeks ago
parent 8b44b6cfc5
commit ed13593569
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> {
static CACHE: OnceLock<bool> = 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<bool> {
static CACHE: OnceLock<bool> = 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)
}

Loading…
Cancel
Save