From b7a900bc187c4be8707b7ca7f2ebd55efc4c407b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 13 Apr 2020 15:31:58 +0200 Subject: [PATCH] Improved codegen for throw path in MemoryGroup.Owned --- .../DiscontiguousBuffers/MemoryGroup{T}.Owned.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs index b42b90d286..276dee7ed0 100644 --- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs +++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroup{T}.Owned.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp.Memory { @@ -69,14 +70,21 @@ namespace SixLabors.ImageSharp.Memory this.IsValid = false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureNotDisposed() { - if (this.memoryOwners == null) + if (this.memoryOwners is null) { - throw new ObjectDisposedException(nameof(MemoryGroup)); + ThrowObjectDisposedException(); } } + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowObjectDisposedException() + { + throw new ObjectDisposedException(nameof(MemoryGroup)); + } + internal static void SwapContents(Owned a, Owned b) { a.EnsureNotDisposed();