Skip to content

Commit

Permalink
Merge pull request #644 from Sergio0694/dev/fix-ref-tracker-exception
Browse files Browse the repository at this point in the history
Improve throw path in ReferenceTracker
  • Loading branch information
Sergio0694 authored Nov 5, 2023
2 parents bef1bb8 + 5eda154 commit 5be5036
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions src/ComputeSharp/Graphics/Interop/ReferenceTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,7 @@ internal Lease GetLease()
{
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;
}
Expand Down

0 comments on commit 5be5036

Please sign in to comment.