From 56a64a6ff027c7c561cbefd26beca824f22c98f3 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 12 Mar 2020 09:52:12 +1300 Subject: [PATCH] Avoid string allocation when converting zero (#19732) --- src/Http/Headers/src/HeaderUtilities.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Http/Headers/src/HeaderUtilities.cs b/src/Http/Headers/src/HeaderUtilities.cs index ff5bb5400c..ac193c0c38 100644 --- a/src/Http/Headers/src/HeaderUtilities.cs +++ b/src/Http/Headers/src/HeaderUtilities.cs @@ -562,6 +562,11 @@ namespace Microsoft.Net.Http.Headers throw new ArgumentOutOfRangeException(nameof(value), value, "The value to be formatted must be non-negative."); } + if (value == 0) + { + return "0"; + } + var position = _int64MaxStringLength; char* charBuffer = stackalloc char[_int64MaxStringLength];