From 5eda15457054a7c336feca11f5d87a514f8f1645 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 5 Nov 2023 16:41:31 +0100 Subject: [PATCH] Improve throw path in ReferenceTracker --- src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs b/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs index cba6b219..e3f866c6 100644 --- a/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs +++ b/src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs @@ -115,15 +115,7 @@ internal struct ReferenceTracker : IDisposable { Lease lease = TryGetLease(out bool leaseTaken); - if (!leaseTaken) - { - // We can't use a throw helper here as we only want to invoke ToString if we - // are about to throw an exception. The JIT will recognize this pattern - // as this method has a single basic block that always throws an exception. - static void Throw(object trackedObject) => throw new ObjectDisposedException(trackedObject.ToString()); - - Throw(this); - } + default(ObjectDisposedException).ThrowIf(!leaseTaken, this.trackedObject); return lease; }