From 6aecd51650796e5c7453290f29d6c49896d8f359 Mon Sep 17 00:00:00 2001 From: Jeremy Kuhne Date: Thu, 11 Jul 2024 18:36:25 -0700 Subject: [PATCH] Improve Value.Type Switch to asserts, which cuts the cost of getting array and array segment type info down to 2.5ns. --- ValuePrototype/Value.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ValuePrototype/Value.cs b/ValuePrototype/Value.cs index 80ba2c8..9492704 100644 --- a/ValuePrototype/Value.cs +++ b/ValuePrototype/Value.cs @@ -13,7 +13,6 @@ public Value(object? value) public readonly Type? Type { - [SkipLocalsInit] get { Type? type; @@ -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[])) { @@ -42,7 +43,7 @@ public readonly Type? Type } else { - ThrowInvalidOperation(); + Debug.Fail($"Unexpected type {type.Name}."); } } }