Skip to content

Commit d21471d

Browse files
authored
Merge pull request #2234 from blouflashdb/#2227
[Chore] Remove InlineningOption from ThrowHelpers
2 parents 22a7cba + f0b83fc commit d21471d

File tree

9 files changed

+1
-130
lines changed

9 files changed

+1
-130
lines changed
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Compression.Zlib;
75

86
internal static class DeflateThrowHelper
97
{
10-
[MethodImpl(InliningOptions.ColdPath)]
118
public static void ThrowAlreadyFinished() => throw new InvalidOperationException("Finish() already called.");
129

13-
[MethodImpl(InliningOptions.ColdPath)]
1410
public static void ThrowAlreadyClosed() => throw new InvalidOperationException("Deflator already closed.");
1511

16-
[MethodImpl(InliningOptions.ColdPath)]
1712
public static void ThrowUnknownCompression() => throw new InvalidOperationException("Unknown compression function.");
1813

19-
[MethodImpl(InliningOptions.ColdPath)]
2014
public static void ThrowNotProcessed() => throw new InvalidOperationException("Old input was not completely processed.");
2115

22-
[MethodImpl(InliningOptions.ColdPath)]
2316
public static void ThrowNull(string name) => throw new ArgumentNullException(name);
2417

25-
[MethodImpl(InliningOptions.ColdPath)]
2618
public static void ThrowOutOfRange(string name) => throw new ArgumentOutOfRangeException(name);
2719

28-
[MethodImpl(InliningOptions.ColdPath)]
2920
public static void ThrowHeapViolated() => throw new InvalidOperationException("Huffman heap invariant violated.");
3021

31-
[MethodImpl(InliningOptions.ColdPath)]
3222
public static void ThrowNoDeflate() => throw new ImageFormatException("Cannot deflate all input.");
3323
}
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Formats.Bmp;
75

86
internal static class BmpThrowHelper
97
{
10-
/// <summary>
11-
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s
12-
/// </summary>
13-
/// <param name="errorMessage">The error message for the exception.</param>
14-
[MethodImpl(MethodImplOptions.NoInlining)]
158
public static void ThrowInvalidImageContentException(string errorMessage)
169
=> throw new InvalidImageContentException(errorMessage);
1710

18-
/// <summary>
19-
/// Cold path optimization for throwing <see cref="NotSupportedException"/>'s
20-
/// </summary>
21-
/// <param name="errorMessage">The error message for the exception.</param>
22-
[MethodImpl(MethodImplOptions.NoInlining)]
2311
public static void ThrowNotSupportedException(string errorMessage)
2412
=> throw new NotSupportedException(errorMessage);
2513
}
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Formats.Gif;
75

86
internal static class GifThrowHelper
97
{
10-
/// <summary>
11-
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s
12-
/// </summary>
13-
/// <param name="errorMessage">The error message for the exception.</param>
14-
[MethodImpl(InliningOptions.ColdPath)]
158
public static void ThrowInvalidImageContentException(string errorMessage)
169
=> throw new InvalidImageContentException(errorMessage);
1710

18-
/// <summary>
19-
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
20-
/// </summary>
21-
/// <param name="errorMessage">The error message for the exception.</param>
22-
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
23-
/// if no inner exception is specified.</param>
24-
[MethodImpl(InliningOptions.ColdPath)]
2511
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException) => throw new InvalidImageContentException(errorMessage, innerException);
2612
}
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,33 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Formats.Jpeg;
75

86
internal static class JpegThrowHelper
97
{
10-
/// <summary>
11-
/// Cold path optimization for throwing <see cref="NotSupportedException"/>'s.
12-
/// </summary>
13-
/// <param name="errorMessage">The error message for the exception.</param>
14-
[MethodImpl(InliningOptions.ColdPath)]
158
public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);
169

17-
/// <summary>
18-
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
19-
/// </summary>
20-
/// <param name="errorMessage">The error message for the exception.</param>
21-
[MethodImpl(InliningOptions.ColdPath)]
2210
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
2311

24-
[MethodImpl(InliningOptions.ColdPath)]
2512
public static void ThrowBadMarker(string marker, int length) => throw new InvalidImageContentException($"Marker {marker} has bad length {length}.");
2613

27-
[MethodImpl(InliningOptions.ColdPath)]
2814
public static void ThrowNotEnoughBytesForMarker(byte marker) => throw new InvalidImageContentException($"Input stream does not have enough bytes to parse declared contents of the {marker:X2} marker.");
2915

30-
[MethodImpl(InliningOptions.ColdPath)]
3116
public static void ThrowBadQuantizationTableIndex(int index) => throw new InvalidImageContentException($"Bad Quantization Table index {index}.");
3217

33-
[MethodImpl(InliningOptions.ColdPath)]
3418
public static void ThrowBadQuantizationTablePrecision(int precision) => throw new InvalidImageContentException($"Unknown Quantization Table precision {precision}.");
3519

36-
[MethodImpl(InliningOptions.ColdPath)]
3720
public static void ThrowBadSampling() => throw new InvalidImageContentException("Bad sampling factor.");
3821

39-
[MethodImpl(InliningOptions.ColdPath)]
4022
public static void ThrowBadSampling(int factor) => throw new InvalidImageContentException($"Bad sampling factor: {factor}");
4123

42-
[MethodImpl(InliningOptions.ColdPath)]
4324
public static void ThrowBadProgressiveScan(int ss, int se, int ah, int al) => throw new InvalidImageContentException($"Invalid progressive parameters Ss={ss} Se={se} Ah={ah} Al={al}.");
4425

45-
[MethodImpl(InliningOptions.ColdPath)]
4626
public static void ThrowInvalidImageDimensions(int width, int height) => throw new InvalidImageContentException($"Invalid image dimensions: {width}x{height}.");
4727

48-
[MethodImpl(InliningOptions.ColdPath)]
4928
public static void ThrowDimensionsTooLarge(int width, int height) => throw new ImageFormatException($"Image is too large to encode at {width}x{height} for JPEG format.");
5029

51-
[MethodImpl(InliningOptions.ColdPath)]
5230
public static void ThrowNotSupportedComponentCount(int componentCount) => throw new NotSupportedException($"Images with {componentCount} components are not supported.");
5331

54-
[MethodImpl(InliningOptions.ColdPath)]
5532
public static void ThrowNotSupportedColorSpace() => throw new NotSupportedException("Image color space could not be deduced.");
5633
}

src/ImageSharp/Formats/Png/PngThrowHelper.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,36 @@
22
// Licensed under the Six Labors Split License.
33

44
using System.Diagnostics.CodeAnalysis;
5-
using System.Runtime.CompilerServices;
65

76
namespace SixLabors.ImageSharp.Formats.Png;
87

9-
/// <summary>
10-
/// Cold path optimizations for throwing png format based exceptions.
11-
/// </summary>
128
internal static class PngThrowHelper
139
{
1410
[DoesNotReturn]
15-
[MethodImpl(InliningOptions.ColdPath)]
1611
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
1712
=> throw new InvalidImageContentException(errorMessage, innerException);
1813

1914
[DoesNotReturn]
20-
[MethodImpl(InliningOptions.ColdPath)]
2115
public static void ThrowNoHeader() => throw new InvalidImageContentException("PNG Image does not contain a header chunk");
2216

2317
[DoesNotReturn]
24-
[MethodImpl(InliningOptions.ColdPath)]
2518
public static void ThrowNoData() => throw new InvalidImageContentException("PNG Image does not contain a data chunk");
2619

2720
[DoesNotReturn]
28-
[MethodImpl(InliningOptions.ColdPath)]
2921
public static void ThrowMissingPalette() => throw new InvalidImageContentException("PNG Image does not contain a palette chunk");
3022

3123
[DoesNotReturn]
32-
[MethodImpl(InliningOptions.ColdPath)]
3324
public static void ThrowInvalidChunkType() => throw new InvalidImageContentException("Invalid PNG data.");
3425

3526
[DoesNotReturn]
36-
[MethodImpl(InliningOptions.ColdPath)]
3727
public static void ThrowInvalidChunkType(string message) => throw new InvalidImageContentException(message);
3828

3929
[DoesNotReturn]
40-
[MethodImpl(InliningOptions.ColdPath)]
4130
public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new InvalidImageContentException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!");
4231

4332
[DoesNotReturn]
44-
[MethodImpl(InliningOptions.ColdPath)]
4533
public static void ThrowNotSupportedColor() => throw new NotSupportedException("Unsupported PNG color type");
4634

4735
[DoesNotReturn]
48-
[MethodImpl(InliningOptions.ColdPath)]
4936
public static void ThrowUnknownFilter() => throw new InvalidImageContentException("Unknown filter type.");
5037
}
Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Formats.Tga;
75

86
internal static class TgaThrowHelper
97
{
10-
/// <summary>
11-
/// Cold path optimization for throwing <see cref="ImageFormatException"/>'s
12-
/// </summary>
13-
/// <param name="errorMessage">The error message for the exception.</param>
14-
[MethodImpl(InliningOptions.ColdPath)]
158
public static void ThrowInvalidImageContentException(string errorMessage)
169
=> throw new InvalidImageContentException(errorMessage);
1710

18-
/// <summary>
19-
/// Cold path optimization for throwing <see cref="ImageFormatException"/>'s
20-
/// </summary>
21-
/// <param name="errorMessage">The error message for the exception.</param>
22-
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference
23-
/// if no inner exception is specified.</param>
24-
[MethodImpl(InliningOptions.ColdPath)]
2511
public static void ThrowInvalidImageContentException(string errorMessage, Exception innerException)
2612
=> throw new InvalidImageContentException(errorMessage, innerException);
2713

28-
/// <summary>
29-
/// Cold path optimization for throwing <see cref="NotSupportedException"/>'s
30-
/// </summary>
31-
/// <param name="errorMessage">The error message for the exception.</param>
32-
[MethodImpl(InliningOptions.ColdPath)]
3314
public static void ThrowNotSupportedException(string errorMessage)
3415
=> throw new NotSupportedException(errorMessage);
3516
}
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Formats.Tiff;
75

8-
/// <summary>
9-
/// Cold path optimizations for throwing tiff format based exceptions.
10-
/// </summary>
116
internal static class TiffThrowHelper
127
{
13-
/// <summary>
14-
/// Cold path optimization for throwing <see cref="ImageFormatException"/>-s
15-
/// </summary>
16-
/// <param name="errorMessage">The error message for the exception.</param>
17-
[MethodImpl(MethodImplOptions.NoInlining)]
188
public static Exception ThrowImageFormatException(string errorMessage) => throw new ImageFormatException(errorMessage);
199

20-
[MethodImpl(InliningOptions.ColdPath)]
2110
public static Exception NotSupportedDecompressor(string compressionType) => throw new NotSupportedException($"Not supported decoder compression method: {compressionType}");
2211

23-
[MethodImpl(InliningOptions.ColdPath)]
2412
public static Exception NotSupportedCompressor(string compressionType) => throw new NotSupportedException($"Not supported encoder compression method: {compressionType}");
2513

26-
[MethodImpl(InliningOptions.ColdPath)]
2714
public static Exception InvalidColorType(string colorType) => throw new NotSupportedException($"Invalid color type: {colorType}");
2815

29-
[MethodImpl(InliningOptions.ColdPath)]
3016
public static Exception ThrowInvalidHeader() => throw new ImageFormatException("Invalid TIFF file header.");
3117

32-
[MethodImpl(InliningOptions.ColdPath)]
3318
public static void ThrowNotSupported(string message) => throw new NotSupportedException(message);
3419

35-
[MethodImpl(InliningOptions.ColdPath)]
3620
public static void ThrowArgumentException(string message) => throw new ArgumentException(message);
3721
}
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4-
using System.Runtime.CompilerServices;
5-
64
namespace SixLabors.ImageSharp.Formats.Webp;
75

86
internal static class WebpThrowHelper
97
{
10-
/// <summary>
11-
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>'s.
12-
/// </summary>
13-
/// <param name="errorMessage">The error message for the exception.</param>
14-
[MethodImpl(InliningOptions.ColdPath)]
158
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
169

17-
/// <summary>
18-
/// Cold path optimization for throwing <see cref="ImageFormatException"/>-s
19-
/// </summary>
20-
/// <param name="errorMessage">The error message for the exception.</param>
21-
[MethodImpl(MethodImplOptions.NoInlining)]
2210
public static void ThrowImageFormatException(string errorMessage) => throw new ImageFormatException(errorMessage);
2311

24-
/// <summary>
25-
/// Cold path optimization for throwing <see cref="NotSupportedException"/>-s
26-
/// </summary>
27-
/// <param name="errorMessage">The error message for the exception.</param>
28-
[MethodImpl(MethodImplOptions.NoInlining)]
2912
public static void ThrowNotSupportedException(string errorMessage) => throw new NotSupportedException(errorMessage);
3013

31-
/// <summary>
32-
/// Cold path optimization for throwing <see cref="InvalidImageContentException"/>-s
33-
/// </summary>
34-
/// <param name="errorMessage">The error message for the exception.</param>
35-
[MethodImpl(MethodImplOptions.NoInlining)]
3614
public static void ThrowInvalidImageDimensions(string errorMessage) => throw new InvalidImageContentException(errorMessage);
3715
}

0 commit comments

Comments
 (0)