Skip to content

Commit

Permalink
Avoid char[] allocation in AltSvcHeaderParser (#103764)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Jun 21, 2024
1 parent 3a8992a commit 6bf2bc8
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 6bf2bc8

Please sign in to comment.