Avoid string allocation when converting zero (#19732)

This commit is contained in:
James Newton-King 2020-03-12 09:52:12 +13:00 committed by GitHub
parent 88b134f877
commit 56a64a6ff0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -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];