Eliminate allocation during HTTP2 path validation (#19273)
This commit is contained in:
parent
1a4dbb7cc5
commit
08a8b38718
|
|
@ -317,9 +317,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const int MaxPathBufferStackAllocSize = 256;
|
||||||
|
|
||||||
// The decoder operates only on raw bytes
|
// The decoder operates only on raw bytes
|
||||||
var pathBuffer = new byte[pathSegment.Length].AsSpan();
|
Span<byte> pathBuffer = pathSegment.Length <= MaxPathBufferStackAllocSize
|
||||||
for (int i = 0; i < pathSegment.Length; i++)
|
// A constant size plus slice generates better code
|
||||||
|
// https://github.com/dotnet/aspnetcore/pull/19273#discussion_r383159929
|
||||||
|
? stackalloc byte[MaxPathBufferStackAllocSize].Slice(0, pathSegment.Length)
|
||||||
|
// TODO - Consider pool here for less than 4096
|
||||||
|
// https://github.com/dotnet/aspnetcore/pull/19273#discussion_r383604184
|
||||||
|
: new byte[pathSegment.Length];
|
||||||
|
|
||||||
|
for (var i = 0; i < pathSegment.Length; i++)
|
||||||
{
|
{
|
||||||
var ch = pathSegment[i];
|
var ch = pathSegment[i];
|
||||||
// The header parser should already be checking this
|
// The header parser should already be checking this
|
||||||
|
|
|
||||||
|
|
@ -691,9 +691,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http3
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
const int MaxPathBufferStackAllocSize = 256;
|
||||||
|
|
||||||
// The decoder operates only on raw bytes
|
// The decoder operates only on raw bytes
|
||||||
var pathBuffer = new byte[pathSegment.Length].AsSpan();
|
Span<byte> pathBuffer = pathSegment.Length <= MaxPathBufferStackAllocSize
|
||||||
for (int i = 0; i < pathSegment.Length; i++)
|
// A constant size plus slice generates better code
|
||||||
|
// https://github.com/dotnet/aspnetcore/pull/19273#discussion_r383159929
|
||||||
|
? stackalloc byte[MaxPathBufferStackAllocSize].Slice(0, pathSegment.Length)
|
||||||
|
// TODO - Consider pool here for less than 4096
|
||||||
|
// https://github.com/dotnet/aspnetcore/pull/19273#discussion_r383604184
|
||||||
|
: new byte[pathSegment.Length];
|
||||||
|
|
||||||
|
for (var i = 0; i < pathSegment.Length; i++)
|
||||||
{
|
{
|
||||||
var ch = pathSegment[i];
|
var ch = pathSegment[i];
|
||||||
// The header parser should already be checking this
|
// The header parser should already be checking this
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue