Skip to content

Commit 13e2d66

Browse files
committed
Changed keys of future's ConcurrentDictionary from IntPtr to long, to prevent unecessary boxing.
- EqualityComparer<IntPtr>.Default returns an ObjectEqualityComparer<IntPtr> which causes boxing - EqualityComparer<long>.Default returns an GenericEqualityComparer<long> which does not
1 parent af8c90c commit 13e2d66

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

FoundationDB.Client/Native/FdbFuture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private static void PostCancellationOnThreadPool(TaskCompletionSource<T> future)
331331
#region Callbacks...
332332

333333
/// <summary>List of all pending futures that have not yet completed</summary>
334-
private static readonly ConcurrentDictionary<IntPtr, FdbFuture<T>> s_futures = new ConcurrentDictionary<IntPtr, FdbFuture<T>>();
334+
private static readonly ConcurrentDictionary<long, FdbFuture<T>> s_futures = new ConcurrentDictionary<long, FdbFuture<T>>();
335335

336336
/// <summary>Internal counter to generated a unique parameter value for each futures</summary>
337337
private static long s_futureCounter;
@@ -355,7 +355,7 @@ internal static IntPtr RegisterCallback([NotNull] FdbFuture<T> future)
355355
#if DEBUG_FUTURES
356356
Contract.Assert(!s_futures.ContainsKey(prm));
357357
#endif
358-
s_futures[prm] = future;
358+
s_futures[prm.ToInt64()] = future;
359359
Interlocked.Increment(ref DebugCounters.CallbackHandlesTotal);
360360
Interlocked.Increment(ref DebugCounters.CallbackHandles);
361361
}
@@ -377,7 +377,7 @@ internal static void UnregisterCallback([NotNull] FdbFuture<T> future)
377377
if (key != IntPtr.Zero)
378378
{
379379
FdbFuture<T> _;
380-
if (s_futures.TryRemove(key, out _))
380+
if (s_futures.TryRemove(key.ToInt64(), out _))
381381
{
382382
Interlocked.Decrement(ref DebugCounters.CallbackHandles);
383383
}
@@ -388,7 +388,7 @@ internal static void UnregisterCallback([NotNull] FdbFuture<T> future)
388388
internal static FdbFuture<T> GetFutureFromCallbackParameter(IntPtr parameter)
389389
{
390390
FdbFuture<T> future;
391-
if (s_futures.TryGetValue(parameter, out future))
391+
if (s_futures.TryGetValue(parameter.ToInt64(), out future))
392392
{
393393
if (future != null && Volatile.Read(ref future.m_key) == parameter)
394394
{

0 commit comments

Comments
 (0)