From 36216363eb08af2ad3fe522caac3b4fe10311a15 Mon Sep 17 00:00:00 2001 From: adamnemecek Date: Sun, 31 Aug 2025 10:18:58 -0700 Subject: [PATCH] Refactored Refresh::combine (#15609) --- crates/uv-cache/src/lib.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/uv-cache/src/lib.rs b/crates/uv-cache/src/lib.rs index 553cf8c2a..a82dfa744 100644 --- a/crates/uv-cache/src/lib.rs +++ b/crates/uv-cache/src/lib.rs @@ -1217,35 +1217,30 @@ impl Refresh { /// Combine two [`Refresh`] policies, taking the "max" of the two policies. #[must_use] pub fn combine(self, other: Self) -> Self { - /// Return the maximum of two timestamps. - fn max(a: Timestamp, b: Timestamp) -> Timestamp { - if a > b { a } else { b } - } - match (self, other) { // If the policy is `None`, return the existing refresh policy. // Take the `max` of the two timestamps. - (Self::None(t1), Self::None(t2)) => Self::None(max(t1, t2)), - (Self::None(t1), Self::All(t2)) => Self::All(max(t1, t2)), + (Self::None(t1), Self::None(t2)) => Self::None(t1.max(t2)), + (Self::None(t1), Self::All(t2)) => Self::All(t1.max(t2)), (Self::None(t1), Self::Packages(packages, paths, t2)) => { - Self::Packages(packages, paths, max(t1, t2)) + Self::Packages(packages, paths, t1.max(t2)) } // If the policy is `All`, refresh all packages. - (Self::All(t1), Self::None(t2)) => Self::All(max(t1, t2)), - (Self::All(t1), Self::All(t2)) => Self::All(max(t1, t2)), - (Self::All(t1), Self::Packages(.., t2)) => Self::All(max(t1, t2)), + (Self::All(t1), Self::None(t2) | Self::All(t2) | Self::Packages(.., t2)) => { + Self::All(t1.max(t2)) + } // If the policy is `Packages`, take the "max" of the two policies. (Self::Packages(packages, paths, t1), Self::None(t2)) => { - Self::Packages(packages, paths, max(t1, t2)) + Self::Packages(packages, paths, t1.max(t2)) } - (Self::Packages(.., t1), Self::All(t2)) => Self::All(max(t1, t2)), + (Self::Packages(.., t1), Self::All(t2)) => Self::All(t1.max(t2)), (Self::Packages(packages1, paths1, t1), Self::Packages(packages2, paths2, t2)) => { Self::Packages( packages1.into_iter().chain(packages2).collect(), paths1.into_iter().chain(paths2).collect(), - max(t1, t2), + t1.max(t2), ) } }