Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/System.Slices/System/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ public static void Requires(bool condition)
{
if (!condition)
{
throw NewArgumentException();
ThrowArgumentException();
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RequiresNonNegative(int n)
{
if (n < 0)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}

Expand All @@ -29,7 +30,7 @@ public static void RequiresInRange(int start, uint length)
{
if ((uint)start >= length)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}

Expand All @@ -38,7 +39,7 @@ public static void RequiresInRange(uint start, uint length)
{
if (start >= length)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}

Expand All @@ -47,7 +48,7 @@ public static void RequiresInInclusiveRange(int start, uint length)
{
if ((uint)start > length)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}

Expand All @@ -56,7 +57,7 @@ public static void RequiresInInclusiveRange(uint start, uint length)
{
if (start > length)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}

Expand All @@ -67,7 +68,7 @@ public static void RequiresInInclusiveRange(int start, int length, uint existing
|| length < 0
|| (uint)(start + length) > existingLength)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}

Expand All @@ -78,21 +79,18 @@ public static void RequiresInInclusiveRange(uint start, uint length, uint existi
|| length < 0
|| (start + length) > existingLength)
{
throw NewArgumentOutOfRangeException();
ThrowArgumentOutOfRangeException();
}
}


[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception NewArgumentException()
private static void ThrowArgumentException()
{
return new ArgumentException();
throw new ArgumentException();
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception NewArgumentOutOfRangeException()
private static void ThrowArgumentOutOfRangeException()
{
return new ArgumentOutOfRangeException();
throw new ArgumentOutOfRangeException();
}
}
}
Expand Down