Skip to content

Commit 56a64a6

Browse files
authored
Avoid string allocation when converting zero (#19732)
1 parent 88b134f commit 56a64a6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Http/Headers/src/HeaderUtilities.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ public unsafe static string FormatNonNegativeInt64(long value)
562562
throw new ArgumentOutOfRangeException(nameof(value), value, "The value to be formatted must be non-negative.");
563563
}
564564

565+
if (value == 0)
566+
{
567+
return "0";
568+
}
569+
565570
var position = _int64MaxStringLength;
566571
char* charBuffer = stackalloc char[_int64MaxStringLength];
567572

0 commit comments

Comments
 (0)