bpf: Use `then_some` instead of `then(|| [...])`

This change fixes the `unnecessary_lazy_evaluations` clippy warning.

Signed-off-by: Michal Rostecki <vadorovsky@gmail.com>
pull/347/head
Michal Rostecki 2 years ago
parent 6f301ac9ca
commit ee15fbbbc5

@ -47,7 +47,7 @@ impl<T> BloomFilter<T> {
value as *const _ as *mut c_void, value as *const _ as *mut c_void,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
#[inline] #[inline]
@ -59,7 +59,7 @@ impl<T> BloomFilter<T> {
flags, flags,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
} }

@ -348,11 +348,11 @@ fn insert<K, V>(def: *mut bpf_map_def, key: &K, value: &V, flags: u64) -> Result
flags, flags,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
#[inline] #[inline]
fn remove<K>(def: *mut bpf_map_def, key: &K) -> Result<(), c_long> { fn remove<K>(def: *mut bpf_map_def, key: &K) -> Result<(), c_long> {
let ret = unsafe { bpf_map_delete_elem(def as *mut _, key as *const _ as *const c_void) }; let ret = unsafe { bpf_map_delete_elem(def as *mut _, key as *const _ as *const c_void) };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }

@ -78,7 +78,7 @@ impl<K, V> LpmTrie<K, V> {
flags, flags,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
#[inline] #[inline]
@ -86,7 +86,7 @@ impl<K, V> LpmTrie<K, V> {
let ret = unsafe { let ret = unsafe {
bpf_map_delete_elem(self.def.get() as *mut _, key as *const _ as *const c_void) bpf_map_delete_elem(self.def.get() as *mut _, key as *const _ as *const c_void)
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
} }

@ -53,14 +53,14 @@ impl<T> Queue<T> {
flags, flags,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
pub fn pop(&self) -> Option<T> { pub fn pop(&self) -> Option<T> {
unsafe { unsafe {
let mut value = mem::MaybeUninit::uninit(); let mut value = mem::MaybeUninit::uninit();
let ret = bpf_map_pop_elem(self.def.get() as *mut _, value.as_mut_ptr() as *mut _); let ret = bpf_map_pop_elem(self.def.get() as *mut _, value.as_mut_ptr() as *mut _);
(ret == 0).then(|| value.assume_init()) (ret == 0).then_some(value.assume_init())
} }
} }
} }

@ -61,7 +61,7 @@ impl<K> SockHash<K> {
flags, flags,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
pub fn redirect_msg(&self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 { pub fn redirect_msg(&self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 {
@ -102,7 +102,7 @@ impl<K> SockHash<K> {
} }
let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags); let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags);
bpf_sk_release(sk); bpf_sk_release(sk);
(ret == 0).then(|| ()).ok_or(1) (ret == 0).then_some(()).ok_or(1)
} }
} }
} }

@ -102,7 +102,7 @@ impl SockMap {
} }
let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags); let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags);
bpf_sk_release(sk); bpf_sk_release(sk);
(ret == 0).then(|| ()).ok_or(1) (ret == 0).then_some(()).ok_or(1)
} }
} }
} }

@ -51,7 +51,7 @@ impl<T> Stack<T> {
flags, flags,
) )
}; };
(ret == 0).then(|| ()).ok_or(ret) (ret == 0).then_some(()).ok_or(ret)
} }
pub fn pop(&mut self) -> Option<T> { pub fn pop(&mut self) -> Option<T> {
@ -61,7 +61,7 @@ impl<T> Stack<T> {
&mut self.def as *mut _ as *mut _, &mut self.def as *mut _ as *mut _,
value.as_mut_ptr() as *mut _, value.as_mut_ptr() as *mut _,
); );
(ret == 0).then(|| value.assume_init()) (ret == 0).then_some(value.assume_init())
} }
} }
} }

Loading…
Cancel
Save