Skip to content

Commit

Permalink
Performance microoptimizations (#2558)
Browse files Browse the repository at this point in the history
Co-authored-by: James Newton-King <[email protected]>
  • Loading branch information
Henr1k80 and JamesNK authored Dec 9, 2024
1 parent 6a3c977 commit b7af033
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 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
2 changes: 1 addition & 1 deletion src/Grpc.AspNetCore.Web/Internal/ServerGrpcWebMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Grpc.AspNetCore.Web.Internal;

internal readonly record struct ServerGrpcWebContext(ServerGrpcWebMode Request, ServerGrpcWebMode Response);

internal enum ServerGrpcWebMode
internal enum ServerGrpcWebMode : byte
{
None,
GrpcWeb,
Expand Down
5 changes: 1 addition & 4 deletions src/Shared/Server/MethodOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ private static void AddCompressionProviders(Dictionary<string, ICompressionProvi
{
foreach (var compressionProvider in compressionProviders)
{
if (!resolvedProviders.ContainsKey(compressionProvider.EncodingName))
{
resolvedProviders.Add(compressionProvider.EncodingName, compressionProvider);
}
resolvedProviders.TryAdd(compressionProvider.EncodingName, compressionProvider);
}
}
}
Expand Down

0 comments on commit b7af033

Please sign in to comment.