InitializeIfRequired();
Debug.Assert(_dictionary != null);
string propertyName = _dictionary.FindValue(child)!.Value.Key;
- if (propertyName.IndexOfAny(ReadStack.SpecialCharacters) != -1)
+ if (propertyName.AsSpan().IndexOfAny(ReadStack.s_specialCharacters) >= 0)
{
path.Add($"['{propertyName}']");
}
{
private static readonly TypeCode s_enumTypeCode = Type.GetTypeCode(typeof(T));
- private static readonly char[] s_specialChars = new[] { ',', ' ' };
-
// Odd type codes are conveniently signed types (for enum backing types).
private static readonly bool s_isSignedEnum = ((int)s_enumTypeCode % 2) == 1;
_nameCacheForReading?.TryAdd(jsonName, value);
// If enum contains special char, make it failed to serialize or deserialize.
- if (name.IndexOfAny(s_specialChars) != -1)
+ if (name.AsSpan().IndexOfAny(',', ' ') >= 0)
{
ThrowHelper.ThrowInvalidOperationException_InvalidEnumTypeWithSpecialChar(typeof(T), name);
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Buffers;
using System.Collections;
-using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[DebuggerDisplay("{DebuggerDisplay,nq}")]
internal struct ReadStack
{
- internal static readonly char[] SpecialCharacters = { '.', ' ', '\'', '/', '"', '[', ']', '(', ')', '\t', '\n', '\r', '\f', '\b', '\\', '\u0085', '\u2028', '\u2029' };
+ private const string SpecialCharacters = ". '/\"[]()\t\n\r\f\b\\\u0085\u2028\u2029";
+#if NET8_0_OR_GREATER
+ internal static readonly IndexOfAnyValues<char> s_specialCharacters = IndexOfAnyValues.Create(SpecialCharacters);
+#else
+ internal static ReadOnlySpan<char> s_specialCharacters => SpecialCharacters.AsSpan();
+#endif
/// <summary>
/// Exposes the stackframe that is currently active.
{
if (propertyName != null)
{
- if (propertyName.IndexOfAny(SpecialCharacters) != -1)
+ if (propertyName.AsSpan().IndexOfAny(s_specialCharacters) >= 0)
{
sb.Append(@"['");
sb.Append(propertyName);