Skip to content

Commit

Permalink
Avoid char[] allocation in AltSvcHeaderParser (dotnet#103764)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored and rzikm committed Jun 24, 2024
1 parent b3258a8 commit feed9c9
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ private static bool TryReadUnknownPercentEncodedAlpnProtocolName(ReadOnlySpan<ch
return true;
}

var builder = new ValueStringBuilder(value.Length <= 128 ? stackalloc char[128] : new char[value.Length]);
var builder = value.Length <= 128 ?
new ValueStringBuilder(stackalloc char[128]) :
new ValueStringBuilder(value.Length);

do
{
Expand All @@ -276,6 +278,7 @@ private static bool TryReadUnknownPercentEncodedAlpnProtocolName(ReadOnlySpan<ch

if ((value.Length - idx) < 3 || !TryReadAlpnHexDigit(value[1], out int hi) || !TryReadAlpnHexDigit(value[2], out int lo))
{
builder.Dispose();
result = null;
return false;
}
Expand Down

0 comments on commit feed9c9

Please sign in to comment.