diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs index 4706b64753c971..ca1567138797ea 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs @@ -149,12 +149,12 @@ public static void ValidateInt32MaxArrayLength(uint length) } } - public static bool AllBitsEqual(this BitArray bitArray, bool value) +#if !NET8_0_OR_GREATER + public static bool HasAllSet(this BitArray bitArray) { - // Optimize this when https://github.com/dotnet/runtime/issues/72999 is fixed for (int i = 0; i < bitArray.Count; i++) { - if (bitArray[i] != value) + if (!bitArray[i]) { return false; } @@ -162,5 +162,6 @@ public static bool AllBitsEqual(this BitArray bitArray, bool value) return true; } +#endif } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs index f09907998f193b..01f9c7bb8a1c1a 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStackFrame.cs @@ -143,7 +143,7 @@ internal void ValidateAllRequiredPropertiesAreRead(JsonTypeInfo typeInfo) { Debug.Assert(RequiredPropertiesSet != null); - if (!RequiredPropertiesSet.AllBitsEqual(true)) + if (!RequiredPropertiesSet.HasAllSet()) { ThrowHelper.ThrowJsonException_JsonRequiredPropertyMissing(typeInfo, RequiredPropertiesSet); }