Browse Source

inline IsOutOfRangeZeroToExclusiveMax

pull/1901/head
Anton Firszov 5 years ago
parent
commit
b0a45f6c08
  1. 9
      src/ImageSharp/Common/Helpers/Numerics.cs
  2. 4
      src/ImageSharp/ImageFrame{TPixel}.cs
  3. 4
      src/ImageSharp/Image{TPixel}.cs
  4. 2
      src/ImageSharp/Memory/Buffer2D{T}.cs

9
src/ImageSharp/Common/Helpers/Numerics.cs

@ -973,14 +973,5 @@ namespace SixLabors.ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsOutOfRange(int value, int min, int max) public static bool IsOutOfRange(int value, int min, int max)
=> (uint)(value - min) > (uint)(max - min); => (uint)(value - min) > (uint)(max - min);
/// <summary>
/// Tells whether input value is outside of the 0..max range.
/// </summary>
/// <param name="value">Value.</param>
/// <param name="max">Maximum value, exclusive.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsOutOfRangeZeroToExclusiveMax(int value, int max)
=> (uint)value >= (uint)max;
} }
} }

4
src/ImageSharp/ImageFrame{TPixel}.cs

@ -443,12 +443,12 @@ namespace SixLabors.ImageSharp
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private void VerifyCoords(int x, int y) private void VerifyCoords(int x, int y)
{ {
if (Numerics.IsOutOfRangeZeroToExclusiveMax(x, this.Width)) if ((uint)x >= (uint)this.Width)
{ {
ThrowArgumentOutOfRangeException(nameof(x)); ThrowArgumentOutOfRangeException(nameof(x));
} }
if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height)) if ((uint)y >= (uint)this.Height)
{ {
ThrowArgumentOutOfRangeException(nameof(y)); ThrowArgumentOutOfRangeException(nameof(y));
} }

4
src/ImageSharp/Image{TPixel}.cs

@ -452,12 +452,12 @@ namespace SixLabors.ImageSharp
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
private void VerifyCoords(int x, int y) private void VerifyCoords(int x, int y)
{ {
if (Numerics.IsOutOfRangeZeroToExclusiveMax(x, this.Width)) if ((uint)x >= (uint)this.Width)
{ {
ThrowArgumentOutOfRangeException(nameof(x)); ThrowArgumentOutOfRangeException(nameof(x));
} }
if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height)) if ((uint)y >= (uint)this.Height)
{ {
ThrowArgumentOutOfRangeException(nameof(y)); ThrowArgumentOutOfRangeException(nameof(y));
} }

2
src/ImageSharp/Memory/Buffer2D{T}.cs

@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Memory
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public Span<T> DangerousGetRowSpan(int y) public Span<T> DangerousGetRowSpan(int y)
{ {
if (Numerics.IsOutOfRangeZeroToExclusiveMax(y, this.Height)) if ((uint)y >= (uint)this.Height)
{ {
this.ThrowYOutOfRangeException(y); this.ThrowYOutOfRangeException(y);
} }

Loading…
Cancel
Save