diff options
author | 2017-04-10 10:40:44 +0200 | |
---|---|---|
committer | 2017-04-10 10:40:44 +0200 | |
commit | 7f0d198e037b58ce6bee3e0d9d48fba757785091 (patch) | |
tree | 2c5c7ce1a6397d24225dc9cd9b4f5dc9081c3981 /src/csharp | |
parent | 921b8968732b320c4113b398ee54503021835fbd (diff) |
avoid boxing of IntPtr
Diffstat (limited to 'src/csharp')
-rw-r--r-- | src/csharp/Grpc.Core/Internal/CompletionRegistry.cs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs b/src/csharp/Grpc.Core/Internal/CompletionRegistry.cs index 7e2f0e9c6c..a4aa8d3ffe 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<CompletionRegistry>(); 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) { @@ -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(); + } + } } } |