Skip to content
Snippets Groups Projects
Commit 830cfd4c authored by Jan Tattermusch's avatar Jan Tattermusch Committed by GitHub
Browse files

Merge pull request #10542 from jtattermusch/intptr_avoid_boxing

Avoid boxing of IntPtr in CompletionRegistry
parents 02e26c98 7f0d198e
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,7 @@ namespace Grpc.Core.Internal ...@@ -51,7 +51,7 @@ namespace Grpc.Core.Internal
static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<CompletionRegistry>(); static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<CompletionRegistry>();
readonly GrpcEnvironment environment; readonly GrpcEnvironment environment;
readonly ConcurrentDictionary<IntPtr, OpCompletionDelegate> dict = new ConcurrentDictionary<IntPtr, OpCompletionDelegate>(); readonly ConcurrentDictionary<IntPtr, OpCompletionDelegate> dict = new ConcurrentDictionary<IntPtr, OpCompletionDelegate>(new IntPtrComparer());
public CompletionRegistry(GrpcEnvironment environment) public CompletionRegistry(GrpcEnvironment environment)
{ {
...@@ -121,5 +121,21 @@ namespace Grpc.Core.Internal ...@@ -121,5 +121,21 @@ namespace Grpc.Core.Internal
} }
} }
} }
/// <summary>
/// IntPtr doesn't implement <c>IEquatable{IntPtr}</c> so we need to use custom comparer to avoid boxing.
/// </summary>
private class IntPtrComparer : IEqualityComparer<IntPtr>
{
public bool Equals(IntPtr x, IntPtr y)
{
return x == y;
}
public int GetHashCode(IntPtr obj)
{
return obj.GetHashCode();
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment