Skip to content

Commit

Permalink
Improve Value.Type
Browse files Browse the repository at this point in the history
Switch to asserts, which cuts the cost of getting array and array segment type info down to 2.5ns.
  • Loading branch information
JeremyKuhne committed Jul 12, 2024
1 parent 6b85d48 commit 6aecd51
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ValuePrototype/Value.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public Value(object? value)

public readonly Type? Type
{
[SkipLocalsInit]
get
{
Type? type;
Expand All @@ -29,8 +28,10 @@ public readonly Type? Type
{
type = _object.GetType();

if (_union.UInt64 != 0 && type.IsArray)
if (_union.UInt64 != 0)
{
Debug.Assert(type.IsArray);

// We have an ArraySegment
if (type == typeof(byte[]))
{
Expand All @@ -42,7 +43,7 @@ public readonly Type? Type
}
else
{
ThrowInvalidOperation();
Debug.Fail($"Unexpected type {type.Name}.");
}
}
}
Expand Down

0 comments on commit 6aecd51

Please sign in to comment.