Skip to content

Commit a3bce08

Browse files
authored
Merge pull request #502 from CommunityToolkit/dev/drop-netcoreapp3.1
Drop .NET Core 3.1 TFM
2 parents adfc48c + ba425c8 commit a3bce08

File tree

35 files changed

+54
-187
lines changed

35 files changed

+54
-187
lines changed

CommunityToolkit.HighPerformance/Buffers/MemoryOwner{T}.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Buffers;
77
using System.Diagnostics;
88
using System.Runtime.CompilerServices;
9-
#if NETCOREAPP3_1_OR_GREATER
9+
#if NET6_0_OR_GREATER
1010
using System.Runtime.InteropServices;
1111
#endif
1212
using CommunityToolkit.HighPerformance.Buffers.Views;
@@ -171,13 +171,13 @@ public Span<T> Span
171171
ThrowObjectDisposedException();
172172
}
173173

174-
#if NETCOREAPP3_1_OR_GREATER
174+
#if NET6_0_OR_GREATER
175175
ref T r0 = ref array!.DangerousGetReferenceAt(this.start);
176176

177-
// On .NET Core runtimes, we can manually create a span from the starting reference to
177+
// On .NET 6+ runtimes, we can manually create a span from the starting reference to
178178
// skip the argument validations, which include an explicit null check, covariance check
179179
// for the array and the actual validation for the starting offset and target length. We
180-
// only do this on .NET Core as we can leverage the runtime-specific array layout to get
180+
// only do this on .NET 6+ as we can leverage the runtime-specific array layout to get
181181
// a fast access to the initial element, which makes this trick worth it. Otherwise, on
182182
// runtimes where we would need to at least access a static field to retrieve the base
183183
// byte offset within an SZ array object, we can get better performance by just using the

CommunityToolkit.HighPerformance/Buffers/SpanOwner{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Buffers;
77
using System.Diagnostics;
88
using System.Runtime.CompilerServices;
9-
#if NETCOREAPP3_1_OR_GREATER
9+
#if NET6_0_OR_GREATER
1010
using System.Runtime.InteropServices;
1111
#endif
1212
using CommunityToolkit.HighPerformance.Buffers.Views;
@@ -141,7 +141,7 @@ public Span<T> Span
141141
[MethodImpl(MethodImplOptions.AggressiveInlining)]
142142
get
143143
{
144-
#if NETCOREAPP3_1_OR_GREATER
144+
#if NET6_0_OR_GREATER
145145
ref T r0 = ref this.array!.DangerousGetReference();
146146

147147
return MemoryMarshal.CreateSpan(ref r0, this.length);

CommunityToolkit.HighPerformance/CommunityToolkit.HighPerformance.csproj

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netstandard2.0;netstandard2.1;netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<PropertyGroup>
@@ -47,23 +47,11 @@
4747

4848
<When Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
4949

50-
<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1, .NET Core 3.1 and .NET 6.
51-
Additionally, also enable trimming support on .NET 6. -->
50+
<!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET 6 and above -->
5251
<PropertyGroup>
5352
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
5453
</PropertyGroup>
5554
</When>
56-
57-
<When Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
58-
<PropertyGroup>
59-
<DefineConstants>NETSTANDARD2_1_OR_GREATER</DefineConstants>
60-
</PropertyGroup>
61-
62-
<!-- .NET Core 3.1 has the Unsafe type, but the version it ships with lacks Unsafe.IsNullRef<T> -->
63-
<ItemGroup>
64-
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
65-
</ItemGroup>
66-
</When>
6755
</Choose>
6856

6957
</Project>

CommunityToolkit.HighPerformance/Extensions/ArrayExtensions.1D.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using System;
66
using System.Runtime.CompilerServices;
7-
#if NETCOREAPP3_1_OR_GREATER
7+
#if NET6_0_OR_GREATER
88
using System.Runtime.InteropServices;
99
#endif
1010
using CommunityToolkit.HighPerformance.Enumerables;
@@ -33,11 +33,6 @@ public static ref T DangerousGetReference<T>(this T[] array)
3333
{
3434
#if NET6_0_OR_GREATER
3535
return ref MemoryMarshal.GetArrayDataReference(array);
36-
#elif NETCOREAPP3_1
37-
RawArrayData? arrayData = Unsafe.As<RawArrayData>(array)!;
38-
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
39-
40-
return ref r0;
4136
#else
4237
IntPtr offset = RuntimeHelpers.GetArrayDataByteOffset<T>();
4338

@@ -60,12 +55,6 @@ public static ref T DangerousGetReferenceAt<T>(this T[] array, int i)
6055
ref T r0 = ref MemoryMarshal.GetArrayDataReference(array);
6156
ref T ri = ref Unsafe.Add(ref r0, (nint)(uint)i);
6257

63-
return ref ri;
64-
#elif NETCOREAPP3_1
65-
RawArrayData? arrayData = Unsafe.As<RawArrayData>(array)!;
66-
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
67-
ref T ri = ref Unsafe.Add(ref r0, (nint)(uint)i);
68-
6958
return ref ri;
7059
#else
7160
IntPtr offset = RuntimeHelpers.GetArrayDataByteOffset<T>();
@@ -76,26 +65,6 @@ public static ref T DangerousGetReferenceAt<T>(this T[] array, int i)
7665
#endif
7766
}
7867

79-
#if NETCOREAPP3_1
80-
// Description taken from CoreCLR: see https://source.dot.net/#System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs,285.
81-
// CLR arrays are laid out in memory as follows (multidimensional array bounds are optional):
82-
// [ sync block || pMethodTable || num components || MD array bounds || array data .. ]
83-
// ^ ^ ^ returned reference
84-
// | \-- ref Unsafe.As<RawArrayData>(array).Data
85-
// \-- array
86-
// The base size of an array includes all the fields before the array data,
87-
// including the sync block and method table. The reference to RawData.Data
88-
// points at the number of components, skipping over these two pointer-sized fields.
89-
[StructLayout(LayoutKind.Sequential)]
90-
private sealed class RawArrayData
91-
{
92-
#pragma warning disable CS0649 // Unassigned fields
93-
public IntPtr Length;
94-
public byte Data;
95-
#pragma warning restore CS0649
96-
}
97-
#endif
98-
9968
/// <summary>
10069
/// Counts the number of occurrences of a given value into a target <typeparamref name="T"/> array instance.
10170
/// </summary>

CommunityToolkit.HighPerformance/Extensions/ArrayExtensions.2D.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ public static ref T DangerousGetReference<T>(this T[,] array)
3030
{
3131
#if NET6_0_OR_GREATER
3232
return ref Unsafe.As<byte, T>(ref MemoryMarshal.GetArrayDataReference(array));
33-
#elif NETCOREAPP3_1
34-
RawArray2DData? arrayData = Unsafe.As<RawArray2DData>(array)!;
35-
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
36-
37-
return ref r0;
3833
#else
3934
IntPtr offset = RuntimeHelpers.GetArray2DDataByteOffset<T>();
4035

@@ -65,13 +60,6 @@ public static ref T DangerousGetReferenceAt<T>(this T[,] array, int i, int j)
6560
ref T r0 = ref Unsafe.As<byte, T>(ref MemoryMarshal.GetArrayDataReference(array));
6661
ref T ri = ref Unsafe.Add(ref r0, index);
6762

68-
return ref ri;
69-
#elif NETCOREAPP3_1
70-
RawArray2DData? arrayData = Unsafe.As<RawArray2DData>(array)!;
71-
nint offset = ((nint)(uint)i * (nint)(uint)arrayData.Width) + (nint)(uint)j;
72-
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
73-
ref T ri = ref Unsafe.Add(ref r0, offset);
74-
7563
return ref ri;
7664
#else
7765
int width = array.GetLength(1);
@@ -84,29 +72,6 @@ public static ref T DangerousGetReferenceAt<T>(this T[,] array, int i, int j)
8472
#endif
8573
}
8674

87-
#if NETCOREAPP3_1
88-
// Description adapted from CoreCLR: see https://source.dot.net/#System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.CoreCLR.cs,285.
89-
// CLR 2D arrays are laid out in memory as follows:
90-
// [ sync block || pMethodTable || Length (padded to IntPtr) || HxW || HxW bounds || array data .. ]
91-
// ^ ^
92-
// | \-- ref Unsafe.As<RawArray2DData>(array).Data
93-
// \-- array
94-
// The length is always padded to IntPtr just like with SZ arrays.
95-
// The total data padding is therefore 20 bytes on x86 (4 + 4 + 4 + 4 + 4), or 24 bytes on x64.
96-
[StructLayout(LayoutKind.Sequential)]
97-
private sealed class RawArray2DData
98-
{
99-
#pragma warning disable CS0649 // Unassigned fields
100-
public IntPtr Length;
101-
public int Height;
102-
public int Width;
103-
public int HeightLowerBound;
104-
public int WidthLowerBound;
105-
public byte Data;
106-
#pragma warning restore CS0649
107-
}
108-
#endif
109-
11075
/// <summary>
11176
/// Returns a <see cref="RefEnumerable{T}"/> over a row in a given 2D <typeparamref name="T"/> array instance.
11277
/// </summary>

CommunityToolkit.HighPerformance/Extensions/ArrayExtensions.3D.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public static ref T DangerousGetReference<T>(this T[,,] array)
2929
{
3030
#if NET6_0_OR_GREATER
3131
return ref Unsafe.As<byte, T>(ref MemoryMarshal.GetArrayDataReference(array));
32-
#elif NETCOREAPP3_1
33-
RawArray3DData? arrayData = Unsafe.As<RawArray3DData>(array)!;
34-
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
35-
36-
return ref r0;
3732
#else
3833
IntPtr offset = RuntimeHelpers.GetArray3DDataByteOffset<T>();
3934

@@ -68,15 +63,6 @@ public static ref T DangerousGetReferenceAt<T>(this T[,,] array, int i, int j, i
6863
ref T r0 = ref Unsafe.As<byte, T>(ref MemoryMarshal.GetArrayDataReference(array));
6964
ref T ri = ref Unsafe.Add(ref r0, index);
7065

71-
return ref ri;
72-
#elif NETCOREAPP3_1
73-
RawArray3DData? arrayData = Unsafe.As<RawArray3DData>(array)!;
74-
nint offset =
75-
((nint)(uint)i * (nint)(uint)arrayData.Height * (nint)(uint)arrayData.Width) +
76-
((nint)(uint)j * (nint)(uint)arrayData.Width) + (nint)(uint)k;
77-
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
78-
ref T ri = ref Unsafe.Add(ref r0, offset);
79-
8066
return ref ri;
8167
#else
8268
int height = array.GetLength(1);
@@ -92,25 +78,6 @@ public static ref T DangerousGetReferenceAt<T>(this T[,,] array, int i, int j, i
9278
#endif
9379
}
9480

95-
#if NETCOREAPP3_1
96-
// See description for this in the 2D partial file.
97-
// Using the CHW naming scheme here (like with RGB images).
98-
[StructLayout(LayoutKind.Sequential)]
99-
private sealed class RawArray3DData
100-
{
101-
#pragma warning disable CS0649 // Unassigned fields
102-
public IntPtr Length;
103-
public int Channel;
104-
public int Height;
105-
public int Width;
106-
public int ChannelLowerBound;
107-
public int HeightLowerBound;
108-
public int WidthLowerBound;
109-
public byte Data;
110-
#pragma warning restore CS0649
111-
}
112-
#endif
113-
11481
#if NETSTANDARD2_1_OR_GREATER
11582
/// <summary>
11683
/// Creates a new <see cref="Memory{T}"/> over an input 3D <typeparamref name="T"/> array.

CommunityToolkit.HighPerformance/Extensions/StringExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static class StringExtensions
2626
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2727
public static ref char DangerousGetReference(this string text)
2828
{
29-
#if NETCOREAPP3_1_OR_GREATER
29+
#if NET6_0_OR_GREATER
3030
return ref Unsafe.AsRef(text.GetPinnableReference());
3131
#else
3232
return ref MemoryMarshal.GetReference(text.AsSpan());
@@ -43,7 +43,7 @@ public static ref char DangerousGetReference(this string text)
4343
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4444
public static ref char DangerousGetReferenceAt(this string text, int i)
4545
{
46-
#if NETCOREAPP3_1_OR_GREATER
46+
#if NET6_0_OR_GREATER
4747
ref char r0 = ref Unsafe.AsRef(text.GetPinnableReference());
4848
#else
4949
ref char r0 = ref MemoryMarshal.GetReference(text.AsSpan());

CommunityToolkit.HighPerformance/Helpers/BitHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Runtime.CompilerServices;
6-
#if NETCOREAPP3_1_OR_GREATER
6+
#if NET6_0_OR_GREATER
77
using System.Runtime.Intrinsics.X86;
88
#endif
99

@@ -224,7 +224,7 @@ public static unsafe uint SetFlag(uint value, int n, bool flag)
224224
[MethodImpl(MethodImplOptions.AggressiveInlining)]
225225
public static uint ExtractRange(uint value, byte start, byte length)
226226
{
227-
#if NETCOREAPP3_1_OR_GREATER
227+
#if NET6_0_OR_GREATER
228228
if (Bmi1.IsSupported)
229229
{
230230
return Bmi1.BitFieldExtract(value, start, length);
@@ -270,7 +270,7 @@ public static uint SetRange(uint value, byte start, byte length, uint flags)
270270
uint loadMask = highBits << start;
271271
uint storeMask = (flags & highBits) << start;
272272

273-
#if NETCOREAPP3_1_OR_GREATER
273+
#if NET6_0_OR_GREATER
274274
if (Bmi1.IsSupported)
275275
{
276276
return Bmi1.AndNot(loadMask, value) | storeMask;
@@ -386,7 +386,7 @@ public static unsafe ulong SetFlag(ulong value, int n, bool flag)
386386
[MethodImpl(MethodImplOptions.AggressiveInlining)]
387387
public static ulong ExtractRange(ulong value, byte start, byte length)
388388
{
389-
#if NETCOREAPP3_1_OR_GREATER
389+
#if NET6_0_OR_GREATER
390390
if (Bmi1.X64.IsSupported)
391391
{
392392
return Bmi1.X64.BitFieldExtract(value, start, length);
@@ -432,7 +432,7 @@ public static ulong SetRange(ulong value, byte start, byte length, ulong flags)
432432
ulong loadMask = highBits << start;
433433
ulong storeMask = (flags & highBits) << start;
434434

435-
#if NETCOREAPP3_1_OR_GREATER
435+
#if NET6_0_OR_GREATER
436436
if (Bmi1.X64.IsSupported)
437437
{
438438
return Bmi1.X64.AndNot(loadMask, value) | storeMask;

CommunityToolkit.HighPerformance/Helpers/Internals/BitOperations.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#if !NET6_0_OR_GREATER
66

77
using System.Runtime.CompilerServices;
8-
#if NETCOREAPP3_1
9-
using System.Runtime.Intrinsics.X86;
10-
using static System.Numerics.BitOperations;
11-
#endif
128

139
namespace CommunityToolkit.HighPerformance.Helpers.Internals;
1410

@@ -29,22 +25,6 @@ internal static class BitOperations
2925
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3026
public static unsafe uint RoundUpToPowerOf2(uint value)
3127
{
32-
#if NETCOREAPP3_1
33-
if (Lzcnt.IsSupported)
34-
{
35-
if (sizeof(nint) == 8)
36-
{
37-
return (uint)(0x1_0000_0000ul >> LeadingZeroCount(value - 1));
38-
}
39-
else
40-
{
41-
int shift = 32 - LeadingZeroCount(value - 1);
42-
43-
return (1u ^ (uint)(shift >> 5)) << shift;
44-
}
45-
}
46-
#endif
47-
4828
// Based on https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
4929
--value;
5030
value |= value >> 1;

CommunityToolkit.HighPerformance/Helpers/Internals/RuntimeHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static nint GetArrayNativeLength(Array array)
7575
return (nint)array.LongLength;
7676
}
7777

78-
#if !NETCOREAPP3_1_OR_GREATER
78+
#if !NET6_0_OR_GREATER
7979
/// <summary>
8080
/// Gets the byte offset to the first <typeparamref name="T"/> element in a SZ array.
8181
/// </summary>

azure-pipelines.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ jobs:
5353

5454
# Test solution #
5555

56+
# Run .NET 7 unit tests
57+
- script: dotnet test --no-build -c $(Build.Configuration) -f net7.0 -l "trx;LogFileName=VSTestResults_net7.0.trx"
58+
displayName: Run .NET 7 unit tests
59+
5660
# Run .NET 6 unit tests
5761
- script: dotnet test --no-build -c $(Build.Configuration) -f net6.0 -l "trx;LogFileName=VSTestResults_net6.0.trx"
5862
displayName: Run .NET 6 unit tests
5963

60-
# Run .NET Core 3.1 unit tests
61-
- script: dotnet test --no-build -c $(Build.Configuration) -f netcoreapp3.1 -l "trx;LogFileName=VSTestResults_netcoreapp3.1.trx"
62-
displayName: Run .NET Core 3.1 unit tests
63-
6464
# Run .NET Framework 4.7.2 unit tests
6565
- script: dotnet test --no-build -c $(Build.Configuration) -f net472 -l "trx;LogFileName=VSTestResults_net472.trx"
6666
displayName: Run .NET Framework 4.7.2 unit tests

tests/CommunityToolkit.Common.UnitTests/CommunityToolkit.Common.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net472;net6.0;net7.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

tests/CommunityToolkit.Diagnostics.UnitTests/CommunityToolkit.Diagnostics.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net472;netcoreapp3.1;net6.0</TargetFrameworks>
4+
<TargetFrameworks>net472;net6.0;net7.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

0 commit comments

Comments
 (0)