From 2e81e14760261d457f23179f8470f4e37e71d1c9 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Mon, 11 Mar 2024 03:29:59 +0000 Subject: [PATCH] lru: using max to simplify the if statement Includes-commit: 6d2613d254688435a9417440fa251467ea6115f8 Replicated-from: https://github.com/cloudflare/pingora/pull/130 Signed-off-by: Xiaobo Liu --- .bleep | 2 +- pingora-lru/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bleep b/.bleep index 74fe28f..8a5222b 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -d2b0975beaec744968a4936eb80483fac65f7e35 \ No newline at end of file +802590d7d04730c3e93f9c2335175990eee1fb92 \ No newline at end of file diff --git a/pingora-lru/src/lib.rs b/pingora-lru/src/lib.rs index bdf330a..d7c31c7 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 {