From b59ef79c16f0a2d34c664f9813dcdabd9ceb98d4 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 1 Oct 2024 15:22:13 +1000 Subject: [PATCH] Avoid unnecessary HealthStatus comparison It's only necessary to check `currentValue == HealthStatus.Unhealthy` when `currentValue` changes. During the first iteration, it is known to be `Healthy`. --- src/HealthChecks/Abstractions/src/HealthReport.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/HealthChecks/Abstractions/src/HealthReport.cs b/src/HealthChecks/Abstractions/src/HealthReport.cs index 829067fb3cfa..15418441ad7b 100644 --- a/src/HealthChecks/Abstractions/src/HealthReport.cs +++ b/src/HealthChecks/Abstractions/src/HealthReport.cs @@ -66,13 +66,13 @@ private static HealthStatus CalculateAggregateStatus(IEnumerable entry.Status) { currentValue = entry.Status; - } - if (currentValue == HealthStatus.Unhealthy) - { - // Game over, man! Game over! - // (We hit the worst possible status, so there's no need to keep iterating) - return currentValue; + if (currentValue == HealthStatus.Unhealthy) + { + // Game over, man! Game over! + // (We hit the worst possible status, so there's no need to keep iterating) + return currentValue; + } } }