Skip to content

Commit

Permalink
Avoid double lookup in dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
Henr1k80 committed Oct 21, 2024
1 parent 8688d5c commit 97583df
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Grpc.AspNetCore.Server/Internal/GrpcProtocolHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Grpc.Core;
Expand Down Expand Up @@ -108,7 +109,7 @@ public static byte[] ParseBinaryHeader(string base64)
switch (base64.Length % 4)
{
case 0:
// base64 has the required padding
// base64 has the required padding
decodable = base64;
break;
case 2:
Expand Down Expand Up @@ -208,11 +209,8 @@ public static AuthContext CreateAuthContext(X509Certificate2 clientCertificate)

static void AddProperty(Dictionary<string, List<AuthProperty>> properties, string name, string value)
{
if (!properties.TryGetValue(name, out var values))
{
values = new List<AuthProperty>();
properties[name] = values;
}
ref var values = ref CollectionsMarshal.GetValueRefOrAddDefault(properties, name, out _);
values ??= [];

values.Add(AuthProperty.Create(name, Encoding.UTF8.GetBytes(value)));
}
Expand Down

0 comments on commit 97583df

Please sign in to comment.