lru: using max to simplify the if statement

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
This commit is contained in:
Xiaobo Liu 2024-03-11 11:29:59 +08:00
parent 36e09ca389
commit 6d2613d254

View file

@ -68,7 +68,7 @@ impl<T, const N: usize> Lru<T, N> {
// Make sure weight is positive otherwise eviction won't work
// TODO: Probably should use NonZeroUsize instead
let weight = if weight == 0 { 1 } else { weight };
let weight = weight.max(1);
let old_weight = unit.admit(key, data, weight);
if old_weight != weight {