From b35693bd03fd5aa2c9d1c2f2991cf20ee2736e7e Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 15 Jan 2025 04:48:52 +0700 Subject: [PATCH 1/9] Add whitespace handling methods to MemoryExtensions Updated the MemoryExtensions class with new methods for efficient whitespace handling, including ContainsAnyWhiteSpace, IndexOfAnyWhiteSpace, and LastIndexOfAnyWhiteSpace. Optimized the IsWhiteSpace method to utilize SearchValues.WhiteSpaces. Added corresponding test cases in StringSearchValues.cs to validate the new functionality. --- .../System.Memory/ref/System.Memory.cs | 5 + .../tests/Span/StringSearchValues.cs | 250 ++++++++++++++++++ .../System/MemoryExtensions.Globalization.cs | 54 +++- .../src/System/SearchValues/SearchValues.cs | 22 ++ 4 files changed, 322 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Memory/ref/System.Memory.cs b/src/libraries/System.Memory/ref/System.Memory.cs index 53d3da5e0441c2..2aea6f21fe34a1 100644 --- a/src/libraries/System.Memory/ref/System.Memory.cs +++ b/src/libraries/System.Memory/ref/System.Memory.cs @@ -277,6 +277,7 @@ public static partial class MemoryExtensions public static bool ContainsAnyInRange(this System.ReadOnlySpan span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] public static bool ContainsAnyInRange(this System.Span span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } + public static bool ContainsAnyWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static void CopyTo(this T[]? source, System.Memory destination) { } public static void CopyTo(this T[]? source, System.Span destination) { } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] @@ -331,6 +332,7 @@ public static void CopyTo(this T[]? source, System.Span destination) { } public static int IndexOfAnyExceptInRange(this System.ReadOnlySpan span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] public static int IndexOfAnyExceptInRange(this System.Span span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } + public static int IndexOfAnyExceptWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static int IndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } public static int IndexOf(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] @@ -340,6 +342,7 @@ public static void CopyTo(this T[]? source, System.Span destination) { } public static int IndexOfAnyInRange(this System.ReadOnlySpan span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] public static int IndexOfAnyInRange(this System.Span span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } + public static int IndexOfAnyWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static bool IsWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static int LastIndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value, System.StringComparison comparisonType) { throw null; } public static int LastIndexOfAny(this System.ReadOnlySpan span, System.Buffers.SearchValues values) where T : System.IEquatable? { throw null; } @@ -372,6 +375,7 @@ public static void CopyTo(this T[]? source, System.Span destination) { } public static int LastIndexOfAnyExceptInRange(this System.ReadOnlySpan span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] public static int LastIndexOfAnyExceptInRange(this System.Span span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } + public static int LastIndexOfAnyExceptWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static int LastIndexOf(this System.ReadOnlySpan span, System.ReadOnlySpan value) where T : System.IEquatable? { throw null; } public static int LastIndexOf(this System.ReadOnlySpan span, T value) where T : System.IEquatable? { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] @@ -381,6 +385,7 @@ public static void CopyTo(this T[]? source, System.Span destination) { } public static int LastIndexOfAnyInRange(this System.ReadOnlySpan span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] public static int LastIndexOfAnyInRange(this System.Span span, T lowInclusive, T highInclusive) where T : System.IComparable { throw null; } + public static int LastIndexOfAnyWhiteSpace(this System.ReadOnlySpan span) { throw null; } public static bool Overlaps(this System.ReadOnlySpan span, System.ReadOnlySpan other) { throw null; } public static bool Overlaps(this System.ReadOnlySpan span, System.ReadOnlySpan other, out int elementOffset) { throw null; } [System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute(-1)] diff --git a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs index f702b0bdcad99d..d5c9b5b1d30cc6 100644 --- a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs +++ b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Buffers; +using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; @@ -10,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; +using TestUtilities; using Xunit; namespace System.Memory.Tests.Span @@ -469,6 +471,254 @@ public static void TestIndexOfAny_RandomInputs() helper.TestRandomInputs(); } + [Fact] + public static void IsWhiteSpace_True() + { + Assert.True(Span.Empty.IsWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.True(CollectionsMarshal.AsSpan(chars).IsWhiteSpace()); + } + + [Fact] + public static void IsWhiteSpace_False() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.Add(' '); + chars.AddRange(chars.ToArray()); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + Assert.False(span.IsWhiteSpace()); + } + } + } + + [Fact] + public static void ContainsAnyWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.Add(' '); + chars.AddRange(chars.ToArray()); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + Assert.True(span.ContainsAnyWhiteSpace()); + } + } + } + + [Fact] + public static void ContainsAnyWhiteSpace_NotFound() + { + Assert.False(Span.Empty.ContainsAnyWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.False(CollectionsMarshal.AsSpan(chars).ContainsAnyWhiteSpace()); + } + + [Fact] + public static void IndexOfAnyWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.Add(' '); + chars.Add(' '); + chars.AddRange(chars.ToArray()); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index, span.IndexOfAnyWhiteSpace()); + } + } + } + + [Fact] + public static void IndexOfAnyWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.IndexOfAnyWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).IndexOfAnyWhiteSpace()); + } + + [Fact] + public static void IndexOfAnyExceptWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.Add(' '); + chars.Add(' '); + chars.AddRange(chars.ToArray()); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index, span.IndexOfAnyExceptWhiteSpace()); + } + } + } + + [Fact] + public static void IndexOfAnyExceptWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.IndexOfAnyExceptWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).IndexOfAnyExceptWhiteSpace()); + } + + [Fact] + public static void LastIndexOfAnyWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.Add(' '); + chars.Add(' '); + chars.AddRange(chars.ToArray()); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index + 1, span.LastIndexOfAnyWhiteSpace()); + } + } + } + + [Fact] + public static void LastIndexOfAnyWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.LastIndexOfAnyWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).LastIndexOfAnyWhiteSpace()); + } + + [Fact] + public static void LastIndexOfAnyExceptWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.Add(' '); + chars.Add(' '); + chars.AddRange(chars.ToArray()); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index + 1, span.LastIndexOfAnyExceptWhiteSpace()); + } + } + } + + [Fact] + public static void LastIndexOfAnyExceptWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.LastIndexOfAnyExceptWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).LastIndexOfAnyExceptWhiteSpace()); + } + [ConditionalFact(nameof(CanTestInvariantCulture))] [SkipOnPlatform(TestPlatforms.LinuxBionic, "Remote executor has problems with exit codes")] public static void TestIndexOfAny_RandomInputs_InvariantCulture() diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs index 5b64d503b836b8..43fa9a6076912b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs @@ -1,6 +1,7 @@ // 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.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; @@ -14,15 +15,8 @@ public static partial class MemoryExtensions /// /// Indicates whether the specified span contains only white-space characters. /// - public static bool IsWhiteSpace(this ReadOnlySpan span) - { - for (int i = 0; i < span.Length; i++) - { - if (!char.IsWhiteSpace(span[i])) - return false; - } - return true; - } + public static bool IsWhiteSpace(this ReadOnlySpan span) => + SearchValues.WhiteSpaces.IndexOfAnyExcept(span) < 0; /// /// Returns a value indicating whether the specified occurs within the . @@ -35,6 +29,16 @@ public static bool Contains(this ReadOnlySpan span, ReadOnlySpan val return IndexOf(span, value, comparisonType) >= 0; } + /// + /// Returns a value indicating whether the specified span contains any + /// white-space characters, and returns if found. If not found, returns + /// . + /// + /// The source span. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => + SearchValues.WhiteSpaces.IndexOfAny(span) >= 0; + /// /// Determines whether this and the specified span have the same characters /// when compared using the specified option. @@ -149,6 +153,22 @@ public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value } } + /// + /// Reports the zero-based index of the first occurrence of any white-space + /// characters in the current , or -1 if not founded. + /// + /// The source span. + public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) => + SearchValues.WhiteSpaces.IndexOfAny(span); + + /// + /// Reports the zero-based index of the first occurrence of any + /// non-white-space characters in the current , or -1 if not founded. + /// + /// The source span. + public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) => + SearchValues.WhiteSpaces.IndexOfAnyExcept(span); + /// /// Reports the zero-based index of the last occurrence of the specified in the current . /// @@ -184,6 +204,22 @@ ref MemoryMarshal.GetReference(value), } } + /// + /// Reports the zero-based index of the last occurrence of any white-space + /// characters in the current , or -1 if not founded. + /// + /// The source span. + public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) => + SearchValues.WhiteSpaces.LastIndexOfAny(span); + + /// + /// Reports the zero-based index of the last occurrence of any + /// non-white-space characters in the current , or -1 if not founded. + /// + /// The source span. + public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) => + SearchValues.WhiteSpaces.LastIndexOfAnyExcept(span); + /// /// Copies the characters from the source span into the destination, converting each character to lowercase, /// using the casing rules of the specified culture. diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs index ab74934a19914a..3fca8c05b75ff4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using System.Runtime.InteropServices; @@ -18,6 +19,27 @@ namespace System.Buffers /// public static class SearchValues { + private static SearchValues? _whiteSpaces; + + internal static SearchValues WhiteSpaces + { + get + { + if (_whiteSpaces is null) + { + List whiteSpaces = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + whiteSpaces.Add((char)i); + } + _whiteSpaces = Create(CollectionsMarshal.AsSpan(whiteSpaces)); + } + + return _whiteSpaces; + } + } + /// /// Creates an optimized representation of used for efficient searching. /// From ad8046303b15e7e5ffabd10574e4c86ba17e1fd1 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 15 Jan 2025 05:17:33 +0700 Subject: [PATCH 2/9] Remove unused TestUtilities import in tests --- src/libraries/System.Memory/tests/Span/StringSearchValues.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs index d5c9b5b1d30cc6..fc7e11240076be 100644 --- a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs +++ b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs @@ -11,7 +11,6 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.DotNet.RemoteExecutor; -using TestUtilities; using Xunit; namespace System.Memory.Tests.Span From e4069c118c49a70f44f339e56a875c73c06e2301 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 15 Jan 2025 05:31:14 +0700 Subject: [PATCH 3/9] Tests bugs have been fixed. --- .../tests/Span/StringSearchValues.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs index fc7e11240076be..130757fd6197db 100644 --- a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs +++ b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs @@ -496,8 +496,8 @@ public static void IsWhiteSpace_False() } var index = chars.Count; - chars.Add(' '); chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); var span = CollectionsMarshal.AsSpan(chars); for (int i = 0; i <= char.MaxValue; i++) @@ -521,8 +521,8 @@ public static void ContainsAnyWhiteSpace_Found() } var index = chars.Count; - chars.Add(' '); chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); var span = CollectionsMarshal.AsSpan(chars); for (int i = 0; i <= char.MaxValue; i++) @@ -561,9 +561,9 @@ public static void IndexOfAnyWhiteSpace_Found() } var index = chars.Count; - chars.Add(' '); - chars.Add(' '); chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); var span = CollectionsMarshal.AsSpan(chars); for (int i = 0; i <= char.MaxValue; i++) @@ -603,9 +603,9 @@ public static void IndexOfAnyExceptWhiteSpace_Found() } var index = chars.Count; - chars.Add(' '); - chars.Add(' '); chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); var span = CollectionsMarshal.AsSpan(chars); for (int i = 0; i <= char.MaxValue; i++) @@ -645,9 +645,9 @@ public static void LastIndexOfAnyWhiteSpace_Found() } var index = chars.Count; - chars.Add(' '); - chars.Add(' '); chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); var span = CollectionsMarshal.AsSpan(chars); for (int i = 0; i <= char.MaxValue; i++) @@ -687,9 +687,9 @@ public static void LastIndexOfAnyExceptWhiteSpace_Found() } var index = chars.Count; - chars.Add(' '); - chars.Add(' '); chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); var span = CollectionsMarshal.AsSpan(chars); for (int i = 0; i <= char.MaxValue; i++) From b495165de058ed40bca6b5c3a793a13ac8397df9 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 15 Jan 2025 17:01:34 +0700 Subject: [PATCH 4/9] Apply suggestions from code review Co-authored-by: Miha Zupan --- .../src/System/MemoryExtensions.Globalization.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs index 43fa9a6076912b..f9fbe47dbd5c7c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs @@ -16,7 +16,7 @@ public static partial class MemoryExtensions /// Indicates whether the specified span contains only white-space characters. /// public static bool IsWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.IndexOfAnyExcept(span) < 0; + !SearchValues.WhiteSpaces.ContainsAnyExcept(span); /// /// Returns a value indicating whether the specified occurs within the . @@ -37,7 +37,7 @@ public static bool Contains(this ReadOnlySpan span, ReadOnlySpan val /// The source span. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.IndexOfAny(span) >= 0; + SearchValues.WhiteSpaces.ContainsAny(span); /// /// Determines whether this and the specified span have the same characters From 3f77a0fa65b6d1b17a11f83c76fcd53227d58a2e Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 15 Jan 2025 18:03:50 +0700 Subject: [PATCH 5/9] Suggestions from code review --- .../tests/ReadOnlySpan/WhiteSpace.cs | 261 ++++++++++++++++++ .../tests/Span/StringSearchValues.cs | 249 ----------------- .../tests/System.Memory.Tests.csproj | 1 + .../System/MemoryExtensions.Globalization.cs | 5 + .../src/System/SearchValues/SearchValues.cs | 22 +- 5 files changed, 269 insertions(+), 269 deletions(-) create mode 100644 src/libraries/System.Memory/tests/ReadOnlySpan/WhiteSpace.cs diff --git a/src/libraries/System.Memory/tests/ReadOnlySpan/WhiteSpace.cs b/src/libraries/System.Memory/tests/ReadOnlySpan/WhiteSpace.cs new file mode 100644 index 00000000000000..09eb02983cf497 --- /dev/null +++ b/src/libraries/System.Memory/tests/ReadOnlySpan/WhiteSpace.cs @@ -0,0 +1,261 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + + +using System.Collections.Generic; +using System.Runtime.InteropServices; +using Xunit; + +namespace System.SpanTests +{ + public static partial class ReadOnlySpanTests + { + [Fact] + public static void IsWhiteSpace_True() + { + Assert.True(Span.Empty.IsWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.True(CollectionsMarshal.AsSpan(chars).IsWhiteSpace()); + } + + [Fact] + public static void IsWhiteSpace_False() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + Assert.False(span.IsWhiteSpace()); + } + } + } + + [Fact] + public static void ContainsAnyWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + Assert.True(span.ContainsAnyWhiteSpace()); + } + } + } + + [Fact] + public static void ContainsAnyWhiteSpace_NotFound() + { + Assert.False(Span.Empty.ContainsAnyWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.False(CollectionsMarshal.AsSpan(chars).ContainsAnyWhiteSpace()); + } + + [Fact] + public static void IndexOfAnyWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index, span.IndexOfAnyWhiteSpace()); + } + } + } + + [Fact] + public static void IndexOfAnyWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.IndexOfAnyWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).IndexOfAnyWhiteSpace()); + } + + [Fact] + public static void IndexOfAnyExceptWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index, span.IndexOfAnyExceptWhiteSpace()); + } + } + } + + [Fact] + public static void IndexOfAnyExceptWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.IndexOfAnyExceptWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).IndexOfAnyExceptWhiteSpace()); + } + + [Fact] + public static void LastIndexOfAnyWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index + 1, span.LastIndexOfAnyWhiteSpace()); + } + } + } + + [Fact] + public static void LastIndexOfAnyWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.LastIndexOfAnyWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).LastIndexOfAnyWhiteSpace()); + } + + [Fact] + public static void LastIndexOfAnyExceptWhiteSpace_Found() + { + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + var index = chars.Count; + chars.AddRange(chars.ToArray()); + chars.Insert(index, ' '); + chars.Insert(index, ' '); + var span = CollectionsMarshal.AsSpan(chars); + + for (int i = 0; i <= char.MaxValue; i++) + { + if (!char.IsWhiteSpace((char)i)) + { + chars[index] = (char)i; + chars[index + 1] = (char)i; + Assert.Equal(index + 1, span.LastIndexOfAnyExceptWhiteSpace()); + } + } + } + + [Fact] + public static void LastIndexOfAnyExceptWhiteSpace_NotFound() + { + Assert.Equal(-1, Span.Empty.LastIndexOfAnyExceptWhiteSpace()); + + List chars = []; + for (int i = 0; i <= char.MaxValue; i++) + { + if (char.IsWhiteSpace((char)i)) + chars.Add((char)i); + } + + Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).LastIndexOfAnyExceptWhiteSpace()); + } + } +} diff --git a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs index 130757fd6197db..f702b0bdcad99d 100644 --- a/src/libraries/System.Memory/tests/Span/StringSearchValues.cs +++ b/src/libraries/System.Memory/tests/Span/StringSearchValues.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Buffers; -using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; @@ -470,254 +469,6 @@ public static void TestIndexOfAny_RandomInputs() helper.TestRandomInputs(); } - [Fact] - public static void IsWhiteSpace_True() - { - Assert.True(Span.Empty.IsWhiteSpace()); - - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - Assert.True(CollectionsMarshal.AsSpan(chars).IsWhiteSpace()); - } - - [Fact] - public static void IsWhiteSpace_False() - { - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - var index = chars.Count; - chars.AddRange(chars.ToArray()); - chars.Insert(index, ' '); - var span = CollectionsMarshal.AsSpan(chars); - - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - { - chars[index] = (char)i; - Assert.False(span.IsWhiteSpace()); - } - } - } - - [Fact] - public static void ContainsAnyWhiteSpace_Found() - { - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - var index = chars.Count; - chars.AddRange(chars.ToArray()); - chars.Insert(index, ' '); - var span = CollectionsMarshal.AsSpan(chars); - - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - { - chars[index] = (char)i; - Assert.True(span.ContainsAnyWhiteSpace()); - } - } - } - - [Fact] - public static void ContainsAnyWhiteSpace_NotFound() - { - Assert.False(Span.Empty.ContainsAnyWhiteSpace()); - - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - Assert.False(CollectionsMarshal.AsSpan(chars).ContainsAnyWhiteSpace()); - } - - [Fact] - public static void IndexOfAnyWhiteSpace_Found() - { - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - var index = chars.Count; - chars.AddRange(chars.ToArray()); - chars.Insert(index, ' '); - chars.Insert(index, ' '); - var span = CollectionsMarshal.AsSpan(chars); - - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - { - chars[index] = (char)i; - chars[index + 1] = (char)i; - Assert.Equal(index, span.IndexOfAnyWhiteSpace()); - } - } - } - - [Fact] - public static void IndexOfAnyWhiteSpace_NotFound() - { - Assert.Equal(-1, Span.Empty.IndexOfAnyWhiteSpace()); - - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).IndexOfAnyWhiteSpace()); - } - - [Fact] - public static void IndexOfAnyExceptWhiteSpace_Found() - { - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - var index = chars.Count; - chars.AddRange(chars.ToArray()); - chars.Insert(index, ' '); - chars.Insert(index, ' '); - var span = CollectionsMarshal.AsSpan(chars); - - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - { - chars[index] = (char)i; - chars[index + 1] = (char)i; - Assert.Equal(index, span.IndexOfAnyExceptWhiteSpace()); - } - } - } - - [Fact] - public static void IndexOfAnyExceptWhiteSpace_NotFound() - { - Assert.Equal(-1, Span.Empty.IndexOfAnyExceptWhiteSpace()); - - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).IndexOfAnyExceptWhiteSpace()); - } - - [Fact] - public static void LastIndexOfAnyWhiteSpace_Found() - { - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - var index = chars.Count; - chars.AddRange(chars.ToArray()); - chars.Insert(index, ' '); - chars.Insert(index, ' '); - var span = CollectionsMarshal.AsSpan(chars); - - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - { - chars[index] = (char)i; - chars[index + 1] = (char)i; - Assert.Equal(index + 1, span.LastIndexOfAnyWhiteSpace()); - } - } - } - - [Fact] - public static void LastIndexOfAnyWhiteSpace_NotFound() - { - Assert.Equal(-1, Span.Empty.LastIndexOfAnyWhiteSpace()); - - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).LastIndexOfAnyWhiteSpace()); - } - - [Fact] - public static void LastIndexOfAnyExceptWhiteSpace_Found() - { - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - var index = chars.Count; - chars.AddRange(chars.ToArray()); - chars.Insert(index, ' '); - chars.Insert(index, ' '); - var span = CollectionsMarshal.AsSpan(chars); - - for (int i = 0; i <= char.MaxValue; i++) - { - if (!char.IsWhiteSpace((char)i)) - { - chars[index] = (char)i; - chars[index + 1] = (char)i; - Assert.Equal(index + 1, span.LastIndexOfAnyExceptWhiteSpace()); - } - } - } - - [Fact] - public static void LastIndexOfAnyExceptWhiteSpace_NotFound() - { - Assert.Equal(-1, Span.Empty.LastIndexOfAnyExceptWhiteSpace()); - - List chars = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - chars.Add((char)i); - } - - Assert.Equal(-1, CollectionsMarshal.AsSpan(chars).LastIndexOfAnyExceptWhiteSpace()); - } - [ConditionalFact(nameof(CanTestInvariantCulture))] [SkipOnPlatform(TestPlatforms.LinuxBionic, "Remote executor has problems with exit codes")] public static void TestIndexOfAny_RandomInputs_InvariantCulture() diff --git a/src/libraries/System.Memory/tests/System.Memory.Tests.csproj b/src/libraries/System.Memory/tests/System.Memory.Tests.csproj index 38b40b284d1b25..933d3f34d31970 100644 --- a/src/libraries/System.Memory/tests/System.Memory.Tests.csproj +++ b/src/libraries/System.Memory/tests/System.Memory.Tests.csproj @@ -193,6 +193,7 @@ + diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs index f9fbe47dbd5c7c..82675ff96bccca 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs @@ -15,6 +15,7 @@ public static partial class MemoryExtensions /// /// Indicates whether the specified span contains only white-space characters. /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWhiteSpace(this ReadOnlySpan span) => !SearchValues.WhiteSpaces.ContainsAnyExcept(span); @@ -158,6 +159,7 @@ public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value /// characters in the current , or -1 if not founded. /// /// The source span. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) => SearchValues.WhiteSpaces.IndexOfAny(span); @@ -166,6 +168,7 @@ public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) => /// non-white-space characters in the current , or -1 if not founded. /// /// The source span. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) => SearchValues.WhiteSpaces.IndexOfAnyExcept(span); @@ -209,6 +212,7 @@ ref MemoryMarshal.GetReference(value), /// characters in the current , or -1 if not founded. /// /// The source span. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) => SearchValues.WhiteSpaces.LastIndexOfAny(span); @@ -217,6 +221,7 @@ public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) => /// non-white-space characters in the current , or -1 if not founded. /// /// The source span. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) => SearchValues.WhiteSpaces.LastIndexOfAnyExcept(span); diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs index 3fca8c05b75ff4..3ac1347913ef1d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs @@ -19,26 +19,8 @@ namespace System.Buffers /// public static class SearchValues { - private static SearchValues? _whiteSpaces; - - internal static SearchValues WhiteSpaces - { - get - { - if (_whiteSpaces is null) - { - List whiteSpaces = []; - for (int i = 0; i <= char.MaxValue; i++) - { - if (char.IsWhiteSpace((char)i)) - whiteSpaces.Add((char)i); - } - _whiteSpaces = Create(CollectionsMarshal.AsSpan(whiteSpaces)); - } - - return _whiteSpaces; - } - } + internal static readonly SearchValues WhiteSpaces = Create( + "\t\n\v\f\r \u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000"); /// /// Creates an optimized representation of used for efficient searching. From 866b91d7743aebab6e9fbc7ed97632faf20229d6 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Wed, 15 Jan 2025 18:07:10 +0700 Subject: [PATCH 6/9] Remove unused namespaces in SearchValues.cs --- .../src/System/SearchValues/SearchValues.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs index 3ac1347913ef1d..608fe03f84a861 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs @@ -1,7 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using System.Runtime.InteropServices; From bb9f9f4173c7ea9c8b470e8786d53fe1fe5805fd Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Fri, 17 Jan 2025 09:14:20 +0700 Subject: [PATCH 7/9] Replaced references to `SearchValues.WhiteSpaces` with `string.SearchValuesStorage.WhiteSpaceChars` in the `MemoryExtensions` class methods. --- .../src/System/MemoryExtensions.Globalization.cs | 12 ++++++------ .../src/System/SearchValues/SearchValues.cs | 3 --- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs index 82675ff96bccca..f9368e86ce16f8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs @@ -17,7 +17,7 @@ public static partial class MemoryExtensions /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsWhiteSpace(this ReadOnlySpan span) => - !SearchValues.WhiteSpaces.ContainsAnyExcept(span); + !string.SearchValuesStorage.WhiteSpaceChars.ContainsAnyExcept(span); /// /// Returns a value indicating whether the specified occurs within the . @@ -38,7 +38,7 @@ public static bool Contains(this ReadOnlySpan span, ReadOnlySpan val /// The source span. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.ContainsAny(span); + string.SearchValuesStorage.WhiteSpaceChars.ContainsAny(span); /// /// Determines whether this and the specified span have the same characters @@ -161,7 +161,7 @@ public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value /// The source span. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.IndexOfAny(span); + string.SearchValuesStorage.WhiteSpaceChars.IndexOfAny(span); /// /// Reports the zero-based index of the first occurrence of any @@ -170,7 +170,7 @@ public static int IndexOfAnyWhiteSpace(this ReadOnlySpan span) => /// The source span. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.IndexOfAnyExcept(span); + string.SearchValuesStorage.WhiteSpaceChars.IndexOfAnyExcept(span); /// /// Reports the zero-based index of the last occurrence of the specified in the current . @@ -214,7 +214,7 @@ ref MemoryMarshal.GetReference(value), /// The source span. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.LastIndexOfAny(span); + string.SearchValuesStorage.WhiteSpaceChars.LastIndexOfAny(span); /// /// Reports the zero-based index of the last occurrence of any @@ -223,7 +223,7 @@ public static int LastIndexOfAnyWhiteSpace(this ReadOnlySpan span) => /// The source span. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOfAnyExceptWhiteSpace(this ReadOnlySpan span) => - SearchValues.WhiteSpaces.LastIndexOfAnyExcept(span); + string.SearchValuesStorage.WhiteSpaceChars.LastIndexOfAnyExcept(span); /// /// Copies the characters from the source span into the destination, converting each character to lowercase, diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs index 608fe03f84a861..ab74934a19914a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/SearchValues.cs @@ -18,9 +18,6 @@ namespace System.Buffers /// public static class SearchValues { - internal static readonly SearchValues WhiteSpaces = Create( - "\t\n\v\f\r \u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000"); - /// /// Creates an optimized representation of used for efficient searching. /// From 5b459979b7f4bf9cfc3af68948a3be1d04a62765 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Fri, 17 Jan 2025 09:16:08 +0700 Subject: [PATCH 8/9] Remove unused using directive in MemoryExtensions This commit removes the `using System.Buffers;` directive from the `MemoryExtensions.Globalization.cs` file, indicating that the functionality provided by the `System.Buffers` namespace is no longer needed or has been replaced by alternative implementations. --- .../src/System/MemoryExtensions.Globalization.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs index f9368e86ce16f8..71cd0bcb2e0ee3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs @@ -1,7 +1,6 @@ // 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.Diagnostics; using System.Globalization; using System.Runtime.CompilerServices; From 8b8e57777a51ba3d708731d60d89d3a9bd2786f6 Mon Sep 17 00:00:00 2001 From: Alexander Radchenko Date: Fri, 20 Feb 2026 05:12:48 +0700 Subject: [PATCH 9/9] Apply suggestion from @PranavSenthilnathan Co-authored-by: Pranav Senthilnathan --- .../src/System/MemoryExtensions.Globalization.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs index 71cd0bcb2e0ee3..5194df760dcd3e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.Globalization.cs @@ -30,11 +30,11 @@ public static bool Contains(this ReadOnlySpan span, ReadOnlySpan val } /// - /// Returns a value indicating whether the specified span contains any - /// white-space characters, and returns if found. If not found, returns - /// . + /// Indicates whether the specified span contains any + /// white-space characters. /// /// The source span. + /// if the span contains any whitespace characters, otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ContainsAnyWhiteSpace(this ReadOnlySpan span) => string.SearchValuesStorage.WhiteSpaceChars.ContainsAny(span);