From 4a7c1fbf100c432f939850a7119ea56498265e50 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Thu, 11 May 2017 11:50:23 +1000 Subject: [PATCH] Use DebugGuard --- src/ImageSharp/Common/Helpers/DebugGuard.cs | 38 +++++++++++++++++++ src/ImageSharp/Common/Helpers/Guard.cs | 38 ------------------- .../Formats/Png/Filters/PaethFilter.cs | 6 +-- .../Formats/Png/Filters/SubFilter.cs | 2 +- .../Formats/Png/Filters/UpFilter.cs | 6 +-- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/ImageSharp/Common/Helpers/DebugGuard.cs b/src/ImageSharp/Common/Helpers/DebugGuard.cs index c1fa461913..f7c83452f6 100644 --- a/src/ImageSharp/Common/Helpers/DebugGuard.cs +++ b/src/ImageSharp/Common/Helpers/DebugGuard.cs @@ -159,5 +159,43 @@ namespace ImageSharp throw new ArgumentException(message, parameterName); } } + + /// + /// Verifies, that the target span is of same size than the 'other' span. + /// + /// The element type of the spans + /// The target span. + /// The 'other' span to compare 'target' to. + /// The name of the parameter that is to be checked. + /// + /// is true + /// + public static void MustBeSameSized(BufferSpan target, BufferSpan other, string parameterName) + where T : struct + { + if (target.Length != other.Length) + { + throw new ArgumentException("Span-s must be the same size!", parameterName); + } + } + + /// + /// Verifies, that the `target` span has the length of 'minSpan', or longer. + /// + /// The element type of the spans + /// The target span. + /// The 'minSpan' span to compare 'target' to. + /// The name of the parameter that is to be checked. + /// + /// is true + /// + public static void MustBeSizedAtLeast(BufferSpan target, BufferSpan minSpan, string parameterName) + where T : struct + { + if (target.Length < minSpan.Length) + { + throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}!", parameterName); + } + } } } \ No newline at end of file diff --git a/src/ImageSharp/Common/Helpers/Guard.cs b/src/ImageSharp/Common/Helpers/Guard.cs index 41a715af9a..cf307e9365 100644 --- a/src/ImageSharp/Common/Helpers/Guard.cs +++ b/src/ImageSharp/Common/Helpers/Guard.cs @@ -230,43 +230,5 @@ namespace ImageSharp throw new ArgumentException(message, parameterName); } } - - /// - /// Verifies, that the target span is of same size than the 'other' span. - /// - /// The element type of the spans - /// The target span. - /// The 'other' span to compare 'target' to. - /// The name of the parameter that is to be checked. - /// - /// is true - /// - public static void MustBeSameSized(BufferSpan target, BufferSpan other, string parameterName) - where T : struct - { - if (target.Length != other.Length) - { - throw new ArgumentException("Span-s must be the same size!", parameterName); - } - } - - /// - /// Verifies, that the `target` span has the length of 'minSpan', or longer. - /// - /// The element type of the spans - /// The target span. - /// The 'minSpan' span to compare 'target' to. - /// The name of the parameter that is to be checked. - /// - /// is true - /// - public static void MustBeSizedAtLeast(BufferSpan target, BufferSpan minSpan, string parameterName) - where T : struct - { - if (target.Length < minSpan.Length) - { - throw new ArgumentException($"Span-s must be at least of length {minSpan.Length}!", parameterName); - } - } } } diff --git a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs index 9f21f0759e..4226596f83 100644 --- a/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/PaethFilter.cs @@ -24,7 +24,7 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Decode(BufferSpan scanline, BufferSpan previousScanline, int bytesPerPixel) { - Guard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); @@ -59,8 +59,8 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Encode(BufferSpan scanline, BufferSpan previousScanline, BufferSpan result, int bytesPerPixel) { - Guard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); - Guard.MustBeSizedAtLeast(result, scanline, nameof(result)); + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); diff --git a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs index 3a5396cb31..d40f261ed1 100644 --- a/src/ImageSharp/Formats/Png/Filters/SubFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/SubFilter.cs @@ -50,7 +50,7 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Encode(BufferSpan scanline, BufferSpan result, int bytesPerPixel) { - Guard.MustBeSizedAtLeast(result, scanline, nameof(result)); + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); ref byte resultBaseRef = ref result.DangerousGetPinnableReference(); diff --git a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs index b30c49c453..fa3ef57daf 100644 --- a/src/ImageSharp/Formats/Png/Filters/UpFilter.cs +++ b/src/ImageSharp/Formats/Png/Filters/UpFilter.cs @@ -22,7 +22,7 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Decode(BufferSpan scanline, BufferSpan previousScanline) { - Guard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference(); @@ -45,8 +45,8 @@ namespace ImageSharp.Formats [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Encode(BufferSpan scanline, BufferSpan previousScanline, BufferSpan result) { - Guard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); - Guard.MustBeSizedAtLeast(result, scanline, nameof(result)); + DebugGuard.MustBeSameSized(scanline, previousScanline, nameof(scanline)); + DebugGuard.MustBeSizedAtLeast(result, scanline, nameof(result)); ref byte scanBaseRef = ref scanline.DangerousGetPinnableReference(); ref byte prevBaseRef = ref previousScanline.DangerousGetPinnableReference();