forked from real-logic/simple-binary-encoding
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use throwhelper to increase change of inlining
- Add a ThrowHelper utility class that provides non-returning methods for throwing exceptions, this in turn helps to reduce the code size, there-by increasing the chances of inlining simple (getter/setter) methods, which has cascading CQ improvments in its own. (See: dotnet/coreclr#6103) - Convert checks in the form of `(x < 0 || x > max)` to `(uint) x > max` to further reduce code-size and increase inlining chances - Update MSTest package deps - Drop netfx.props (which I introduces in a previous PR to support building on linux) and replace with the now standard/canonical way of referencing NetFX BCL on all platforms with a <PackageReference> - closes real-logic#588
- Loading branch information
Showing
5 changed files
with
66 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
|
||
namespace Org.SbeTool.Sbe.Dll | ||
{ | ||
/// <summary> | ||
/// Helper class that provides non-returning methods that throw common exception | ||
/// from the generated C# code | ||
/// </summary> | ||
public class ThrowHelper | ||
{ | ||
/// <summary> | ||
/// Throws a <see cref="ArgumentOutOfRangeException"/> when the "count" parameter is out of range | ||
/// </summary> | ||
/// <param name="count">the parameter that triggered the exception</param> | ||
public static void ThrowCountOutOfRangeException(int count) => | ||
throw new ArgumentOutOfRangeException("count", $"Outside allowed range: count={count}"); | ||
|
||
/// <summary> | ||
/// Throws a <see cref="InvalidOperationException"/> when an invalid operation is invoked on a message (for example: enumerating a group past it's maximal count) | ||
/// </summary> | ||
public static void ThrowInvalidOperationException() => | ||
throw new InvalidOperationException(); | ||
|
||
/// <summary> | ||
/// Throws a <see cref="IndexOutOfRangeException" /> when the "index" parameter is out of range | ||
/// </summary> | ||
/// <param name="index">the parameter that triggered the exception</param> | ||
public static void ThrowIndexOutOfRangeException(int index) => | ||
throw new IndexOutOfRangeException($"index out of range: index={index}"); | ||
|
||
/// <summary> | ||
/// Throws a <see cref="ArgumentOutOfRangeException"/> when a too-small <see cref="Span{T}"/> | ||
/// is provided to a getter | ||
/// </summary> | ||
/// <param name="length">The length of the too-small Span</param> | ||
public static void ThrowWhenSpanLengthTooSmall(int length) => | ||
throw new ArgumentOutOfRangeException("dst", $"dst.Length={length} is too small."); | ||
|
||
/// <summary> | ||
/// Throws a <see cref="ArgumentOutOfRangeException"/> when a too-large <see cref="Span{T}"/> | ||
/// is provided to a setter | ||
/// </summary> | ||
/// <param name="length">The length of the too-large Span</param> | ||
public static void ThrowWhenSpanLengthTooLarge(int length) => | ||
throw new ArgumentOutOfRangeException("src", $"src.Length={length} is too large."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters