From 7f0d198e037b58ce6bee3e0d9d48fba757785091 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 10 Apr 2017 10:40:44 +0200 Subject: [PATCH] avoid boxing of IntPtr --- .../Grpc.Core/Internal/CompletionRegistry.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs index 7e2f0e9c6c9..a4aa8d3ffe4 100644 --- a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs +++ b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs @@ -51,7 +51,7 @@ namespace Grpc.Core.Internal static readonly ILogger Logger = GrpcEnvironment.Logger.ForType(); readonly GrpcEnvironment environment; - readonly ConcurrentDictionary dict = new ConcurrentDictionary(); + readonly ConcurrentDictionary dict = new ConcurrentDictionary(new IntPtrComparer()); public CompletionRegistry(GrpcEnvironment environment) { @@ -121,5 +121,21 @@ namespace Grpc.Core.Internal } } } + + /// + /// IntPtr doesn't implement IEquatable{IntPtr} so we need to use custom comparer to avoid boxing. + /// + private class IntPtrComparer : IEqualityComparer + { + public bool Equals(IntPtr x, IntPtr y) + { + return x == y; + } + + public int GetHashCode(IntPtr obj) + { + return obj.GetHashCode(); + } + } } }