Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 992a960

Browse files
ahsonkhanjoshfree
authored andcommitted
Add MemoryExtensions to CoreLib along with necessary SpanHelpers (#16521)
* Add MemoryExtensions to CoreLib along with necessary SpanHelpers * Make the newly added AsSpan/AsMemory into array extension methods. * Remove StringSpanHelpers.Trim * Leftover AsReadOnlySpan -> AsSpan for *Unix.cs files * Address PR feedback. * Remove duplicate methods in the Span class. * Temporarily disable AsBytes SpanBench test. * Add back AsBytes * Re-enable AsBytes SpanBench test Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
1 parent 8f01f4f commit 992a960

File tree

11 files changed

+4103
-1046
lines changed

11 files changed

+4103
-1046
lines changed

src/Common/src/CoreLib/System.Private.CoreLib.Shared.projitems

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241
<Compile Include="$(MSBuildThisFileDirectory)System\MemberAccessException.cs" />
242242
<Compile Include="$(MSBuildThisFileDirectory)System\Memory.cs" />
243243
<Compile Include="$(MSBuildThisFileDirectory)System\MemoryDebugView.cs" />
244+
<Compile Include="$(MSBuildThisFileDirectory)System\MemoryExtensions.cs" />
245+
<Compile Include="$(MSBuildThisFileDirectory)System\MemoryExtensions.Fast.cs" />
244246
<Compile Include="$(MSBuildThisFileDirectory)System\MethodAccessException.cs" />
245247
<Compile Include="$(MSBuildThisFileDirectory)System\MidpointRounding.cs" />
246248
<Compile Include="$(MSBuildThisFileDirectory)System\MissingMethodException.cs" />
@@ -485,8 +487,12 @@
485487
<Compile Include="$(MSBuildThisFileDirectory)System\Single.cs" />
486488
<Compile Include="$(MSBuildThisFileDirectory)System\Span.cs" />
487489
<Compile Include="$(MSBuildThisFileDirectory)System\Span.Fast.cs" />
488-
<Compile Include="$(MSBuildThisFileDirectory)System\SpanDebugView.cs" />
489490
<Compile Include="$(MSBuildThisFileDirectory)System\Span.NonGeneric.cs" />
491+
<Compile Include="$(MSBuildThisFileDirectory)System\SpanDebugView.cs" />
492+
<Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.cs" />
493+
<Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.BinarySearch.cs" />
494+
<Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.Byte.cs" />
495+
<Compile Include="$(MSBuildThisFileDirectory)System\SpanHelpers.T.cs" />
490496
<Compile Include="$(MSBuildThisFileDirectory)System\String.Manipulation.cs" />
491497
<Compile Include="$(MSBuildThisFileDirectory)System\String.Searching.cs" />
492498
<Compile Include="$(MSBuildThisFileDirectory)System\StringSpanHelpers.cs" />

src/Common/src/CoreLib/System/Double.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFor
345345
bool success = Number.TryParseDouble(s, style, info, out result);
346346
if (!success)
347347
{
348-
ReadOnlySpan<char> sTrim = StringSpanHelpers.Trim(s);
348+
ReadOnlySpan<char> sTrim = s.Trim();
349349
if (StringSpanHelpers.Equals(sTrim, info.PositiveInfinitySymbol))
350350
{
351351
result = PositiveInfinity;

src/Common/src/CoreLib/System/MemoryExtensions.Fast.cs

Lines changed: 540 additions & 0 deletions
Large diffs are not rendered by default.

src/Common/src/CoreLib/System/MemoryExtensions.cs

Lines changed: 1170 additions & 0 deletions
Large diffs are not rendered by default.

src/Common/src/CoreLib/System/Span.Fast.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ public void Clear()
162162
{
163163
if (RuntimeHelpers.IsReferenceOrContainsReferences<T>())
164164
{
165-
Span.ClearWithReferences(ref Unsafe.As<T, IntPtr>(ref _pointer.Value), (nuint)_length * (nuint)(Unsafe.SizeOf<T>() / sizeof(nuint)));
165+
SpanHelpers.ClearWithReferences(ref Unsafe.As<T, IntPtr>(ref _pointer.Value), (nuint)_length * (nuint)(Unsafe.SizeOf<T>() / sizeof(nuint)));
166166
}
167167
else
168168
{
169-
Span.ClearWithoutReferences(ref Unsafe.As<T, byte>(ref _pointer.Value), (nuint)_length * (nuint)Unsafe.SizeOf<T>());
169+
SpanHelpers.ClearWithoutReferences(ref Unsafe.As<T, byte>(ref _pointer.Value), (nuint)_length * (nuint)Unsafe.SizeOf<T>());
170170
}
171171
}
172172

0 commit comments

Comments
 (0)