diff options
author | Jan Tattermusch <jtattermusch@users.noreply.github.com> | 2017-04-11 16:58:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-11 16:58:00 +0200 |
commit | 830cfd4c585f9441f40f0f791ef41ad6fdbf8c3e (patch) | |
tree | eec2b748e940b7b96e71f6d3a95cafb7afd8e346 /src | |
parent | 02e26c98f4acbf9f3e9ba1029b4e4673e454aca8 (diff) | |
parent | 7f0d198e037b58ce6bee3e0d9d48fba757785091 (diff) |
Merge pull request #10542 from jtattermusch/intptr_avoid_boxing
Avoid boxing of IntPtr in CompletionRegistry
Diffstat (limited to 'src')
-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(); + } + } } } |