From 19b52bdc8b5b9eeb2ed28d45cbac75a91b593e76 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Tue, 5 Mar 2019 00:44:21 +0000 Subject: [PATCH] Elide bounds check for MethodToString (#7887) --- .../Core/src/Internal/Infrastructure/HttpUtilities.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs index 082e2de0d7..7c5276259e 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.cs @@ -410,10 +410,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure } public static string MethodToString(HttpMethod method) { - int methodIndex = (int)method; - if (methodIndex >= 0 && methodIndex <= 8) + var methodIndex = (int)method; + var methodNames = _methodNames; + if ((uint)methodIndex < (uint)methodNames.Length) { - return _methodNames[methodIndex]; + return methodNames[methodIndex]; } return null; }