From 6d2613d254688435a9417440fa251467ea6115f8 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Mon, 11 Mar 2024 11:29:59 +0800 Subject: [PATCH] lru: using max to simplify the if statement Signed-off-by: Xiaobo Liu --- pingora-lru/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pingora-lru/src/lib.rs b/pingora-lru/src/lib.rs index a2ddf40..1204c1a 100644 --- a/pingora-lru/src/lib.rs +++ b/pingora-lru/src/lib.rs @@ -68,7 +68,7 @@ impl Lru { // 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 {