Browse Source

Use ThrowHelper

pull/1190/head
Brian Popow 6 years ago
parent
commit
193dafe65a
  1. 5
      src/ImageSharp/Formats/Gif/GifDecoder.cs
  2. 12
      src/ImageSharp/Formats/Gif/GifThrowHelper.cs
  3. 5
      src/ImageSharp/Formats/Jpeg/JpegDecoder.cs
  4. 9
      src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs
  5. 5
      src/ImageSharp/Formats/Png/PngDecoder.cs
  6. 4
      src/ImageSharp/Formats/Png/PngThrowHelper.cs
  7. 5
      src/ImageSharp/Formats/Tga/TgaDecoder.cs
  8. 14
      src/ImageSharp/Formats/Tga/TgaThrowHelper.cs

5
src/ImageSharp/Formats/Gif/GifDecoder.cs

@ -38,7 +38,10 @@ namespace SixLabors.ImageSharp.Formats.Gif
{
Size dims = decoder.Dimensions;
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
GifThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
// Not reachable, as the previous statement will throw a exception.
return null;
}
}

12
src/ImageSharp/Formats/Gif/GifThrowHelper.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.Gif
@ -11,8 +12,17 @@ namespace SixLabors.ImageSharp.Formats.Gif
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)]
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage)
=> throw new InvalidImageContentException(errorMessage);
/// <summary>
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
}
}

5
src/ImageSharp/Formats/Jpeg/JpegDecoder.cs

@ -32,7 +32,10 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{
(int w, int h) = (decoder.ImageWidth, decoder.ImageHeight);
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
JpegThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex);
// Not reachable, as the previous statement will throw a exception.
return null;
}
}

9
src/ImageSharp/Formats/Jpeg/JpegThrowHelper.cs

@ -15,6 +15,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
/// <summary>
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
/// <summary>
/// Cold path optimization for throwing <see cref="NotImplementedException"/>'s
/// </summary>

5
src/ImageSharp/Formats/Png/PngDecoder.cs

@ -54,7 +54,10 @@ namespace SixLabors.ImageSharp.Formats.Png
{
Size dims = decoder.Dimensions;
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
PngThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
// Not reachable, as the previous statement will throw a exception.
return null;
}
}

4
src/ImageSharp/Formats/Png/PngThrowHelper.cs

@ -11,6 +11,10 @@ namespace SixLabors.ImageSharp.Formats.Png
/// </summary>
internal static class PngThrowHelper
{
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
=> throw new InvalidImageContentException(errorMessage, innerException);
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNoHeader() => throw new InvalidImageContentException("PNG Image does not contain a header chunk");

5
src/ImageSharp/Formats/Tga/TgaDecoder.cs

@ -28,7 +28,10 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
Size dims = decoder.Dimensions;
throw new InvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
TgaThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex);
// Not reachable, as the previous statement will throw a exception.
return null;
}
}

14
src/ImageSharp/Formats/Tga/TgaThrowHelper.cs

@ -12,15 +12,25 @@ namespace SixLabors.ImageSharp.Formats.Tga
/// Cold path optimization for throwing <see cref="ImageFormatException"/>'s
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)]
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage)
=> throw new InvalidImageContentException(errorMessage);
/// <summary>
/// Cold path optimization for throwing <see cref="ImageFormatException"/>'s
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
/// if no inner exception is specified.</param>
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
=> throw new InvalidImageContentException(errorMessage, innerException);
/// <summary>
/// Cold path optimization for throwing <see cref="NotSupportedException"/>'s
/// </summary>
/// <param name="errorMessage">The error message for the exception.</param>
[MethodImpl(MethodImplOptions.NoInlining)]
[MethodImpl(InliningOptions.ColdPath)]
public static void ThrowNotSupportedException(string errorMessage)
=> throw new NotSupportedException(errorMessage);
}

Loading…
Cancel
Save