Skip to content

Commit 951774d

Browse files
authored
Merge branch 'master' into jamesmcroft/3506-carousel-automation
2 parents 41491ee + 9b75c9f commit 951774d

File tree

97 files changed

+1322
-557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1322
-557
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->
22

3+
<!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->
4+
5+
36
## Fixes #
47
<!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. -->
58

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
#if !NET5_0
6+
7+
namespace System.Runtime.CompilerServices
8+
{
9+
/// <summary>
10+
/// Used to indicate to the compiler that the <c>.locals init</c> flag should not be set in method headers.
11+
/// </summary>
12+
/// <remarks>Internal copy of the .NET 5 attribute.</remarks>
13+
[AttributeUsage(
14+
AttributeTargets.Module |
15+
AttributeTargets.Class |
16+
AttributeTargets.Struct |
17+
AttributeTargets.Interface |
18+
AttributeTargets.Constructor |
19+
AttributeTargets.Method |
20+
AttributeTargets.Property |
21+
AttributeTargets.Event,
22+
Inherited = false)]
23+
internal sealed class SkipLocalsInitAttribute : Attribute
24+
{
25+
}
26+
}
27+
28+
#endif

Microsoft.Toolkit.HighPerformance/Buffers/MemoryOwner{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Diagnostics;
88
using System.Diagnostics.Contracts;
99
using System.Runtime.CompilerServices;
10-
#if NETCORE_RUNTIME
10+
#if NETCORE_RUNTIME || NET5_0
1111
using System.Runtime.InteropServices;
1212
#endif
1313
using Microsoft.Toolkit.HighPerformance.Buffers.Views;
@@ -183,7 +183,7 @@ public Span<T> Span
183183
ThrowObjectDisposedException();
184184
}
185185

186-
#if NETCORE_RUNTIME
186+
#if NETCORE_RUNTIME || NET5_0
187187
ref T r0 = ref array!.DangerousGetReferenceAt(this.start);
188188

189189
// On .NET Core runtimes, we can manually create a span from the starting reference to

Microsoft.Toolkit.HighPerformance/Buffers/SpanOwner{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using System.Diagnostics;
88
using System.Diagnostics.Contracts;
99
using System.Runtime.CompilerServices;
10-
#if NETCORE_RUNTIME
10+
#if NETCORE_RUNTIME || NET5_0
1111
using System.Runtime.InteropServices;
1212
#endif
1313
using Microsoft.Toolkit.HighPerformance.Buffers.Views;
@@ -148,7 +148,7 @@ public Span<T> Span
148148
[MethodImpl(MethodImplOptions.AggressiveInlining)]
149149
get
150150
{
151-
#if NETCORE_RUNTIME
151+
#if NETCORE_RUNTIME || NET5_0
152152
ref T r0 = ref array!.DangerousGetReference();
153153

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

Microsoft.Toolkit.HighPerformance/Buffers/StringPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

Microsoft.Toolkit.HighPerformance/Extensions/ArrayExtensions.1D.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66
using System.Diagnostics.Contracts;
77
using System.Runtime.CompilerServices;
8-
#if NETCORE_RUNTIME
8+
#if NETCORE_RUNTIME || NET5_0
99
using System.Runtime.InteropServices;
1010
#endif
1111
using Microsoft.Toolkit.HighPerformance.Enumerables;
@@ -30,7 +30,9 @@ public static partial class ArrayExtensions
3030
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3131
public static ref T DangerousGetReference<T>(this T[] array)
3232
{
33-
#if NETCORE_RUNTIME
33+
#if NET5_0
34+
return ref MemoryMarshal.GetArrayDataReference(array);
35+
#elif NETCORE_RUNTIME
3436
var arrayData = Unsafe.As<RawArrayData>(array)!;
3537
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
3638

@@ -54,7 +56,12 @@ public static ref T DangerousGetReference<T>(this T[] array)
5456
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5557
public static ref T DangerousGetReferenceAt<T>(this T[] array, int i)
5658
{
57-
#if NETCORE_RUNTIME
59+
#if NET5_0
60+
ref T r0 = ref MemoryMarshal.GetArrayDataReference(array);
61+
ref T ri = ref Unsafe.Add(ref r0, (nint)(uint)i);
62+
63+
return ref ri;
64+
#elif NETCORE_RUNTIME
5865
var arrayData = Unsafe.As<RawArrayData>(array)!;
5966
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
6067
ref T ri = ref Unsafe.Add(ref r0, (nint)(uint)i);
@@ -203,7 +210,7 @@ public static bool IsCovariant<T>(this T[] array)
203210
/// <summary>
204211
/// Throws an <see cref="OverflowException"/> when the "column" parameter is invalid.
205212
/// </summary>
206-
public static void ThrowOverflowException()
213+
private static void ThrowOverflowException()
207214
{
208215
throw new OverflowException();
209216
}

Microsoft.Toolkit.HighPerformance/Extensions/ArrayExtensions.2D.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,15 +451,15 @@ private static void ThrowArrayTypeMismatchException()
451451
/// <summary>
452452
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "row" parameter is invalid.
453453
/// </summary>
454-
public static void ThrowArgumentOutOfRangeExceptionForRow()
454+
private static void ThrowArgumentOutOfRangeExceptionForRow()
455455
{
456456
throw new ArgumentOutOfRangeException("row");
457457
}
458458

459459
/// <summary>
460460
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "column" parameter is invalid.
461461
/// </summary>
462-
public static void ThrowArgumentOutOfRangeExceptionForColumn()
462+
private static void ThrowArgumentOutOfRangeExceptionForColumn()
463463
{
464464
throw new ArgumentOutOfRangeException("column");
465465
}

Microsoft.Toolkit.HighPerformance/Extensions/ArrayExtensions.3D.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public static bool IsCovariant<T>(this T[,,] array)
316316
/// <summary>
317317
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "depth" parameter is invalid.
318318
/// </summary>
319-
public static void ThrowArgumentOutOfRangeExceptionForDepth()
319+
private static void ThrowArgumentOutOfRangeExceptionForDepth()
320320
{
321321
throw new ArgumentOutOfRangeException("depth");
322322
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Diagnostics.Contracts;
6+
using System.IO;
7+
using System.Runtime.CompilerServices;
8+
using Microsoft.Toolkit.HighPerformance.Buffers;
9+
using Microsoft.Toolkit.HighPerformance.Streams;
10+
using Microsoft.Toolkit.HighPerformance.Streams.Sources;
11+
12+
namespace Microsoft.Toolkit.HighPerformance.Extensions
13+
{
14+
/// <summary>
15+
/// Helpers for working with the <see cref="ArrayPoolBufferWriter{T}"/> type.
16+
/// </summary>
17+
public static class ArrayPoolBufferWriterExtensions
18+
{
19+
/// <summary>
20+
/// Returns a <see cref="Stream"/> that can be used to write to a target an <see cref="ArrayPoolBufferWriter{T}"/> of <see cref="byte"/> instance.
21+
/// </summary>
22+
/// <param name="writer">The target <see cref="ArrayPoolBufferWriter{T}"/> instance.</param>
23+
/// <returns>A <see cref="Stream"/> wrapping <paramref name="writer"/> and writing data to its underlying buffer.</returns>
24+
/// <remarks>The returned <see cref="Stream"/> can only be written to and does not support seeking.</remarks>
25+
[Pure]
26+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
27+
public static Stream AsStream(this ArrayPoolBufferWriter<byte> writer)
28+
{
29+
return new IBufferWriterStream<ArrayBufferWriterOwner>(new ArrayBufferWriterOwner(writer));
30+
}
31+
}
32+
}

Microsoft.Toolkit.HighPerformance/Extensions/BoolExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public static class BoolExtensions
2121
/// <remarks>This method does not contain branching instructions.</remarks>
2222
[Pure]
2323
[MethodImpl(MethodImplOptions.AggressiveInlining)]
24-
public static byte ToByte(this bool flag)
24+
public static unsafe byte ToByte(this bool flag)
2525
{
26-
return Unsafe.As<bool, byte>(ref flag);
26+
return *(byte*)&flag;
2727
}
2828

2929
/// <summary>
@@ -35,9 +35,9 @@ public static byte ToByte(this bool flag)
3535
[Pure]
3636
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3737
[Obsolete("Use ToByte instead.")]
38-
public static int ToInt(this bool flag)
38+
public static unsafe int ToInt(this bool flag)
3939
{
40-
return Unsafe.As<bool, byte>(ref flag);
40+
return *(byte*)&flag;
4141
}
4242

4343
/// <summary>
@@ -56,9 +56,9 @@ public static int ToInt(this bool flag)
5656
/// </remarks>
5757
[Pure]
5858
[MethodImpl(MethodImplOptions.AggressiveInlining)]
59-
public static int ToBitwiseMask32(this bool flag)
59+
public static unsafe int ToBitwiseMask32(this bool flag)
6060
{
61-
byte rangeFlag = Unsafe.As<bool, byte>(ref flag);
61+
byte rangeFlag = *(byte*)&flag;
6262
int
6363
negativeFlag = rangeFlag - 1,
6464
mask = ~negativeFlag;
@@ -75,9 +75,9 @@ public static int ToBitwiseMask32(this bool flag)
7575
/// <remarks>This method does not contain branching instructions. See additional note in <see cref="ToBitwiseMask32"/>.</remarks>
7676
[Pure]
7777
[MethodImpl(MethodImplOptions.AggressiveInlining)]
78-
public static long ToBitwiseMask64(this bool flag)
78+
public static unsafe long ToBitwiseMask64(this bool flag)
7979
{
80-
byte rangeFlag = Unsafe.As<bool, byte>(ref flag);
80+
byte rangeFlag = *(byte*)&flag;
8181
long
8282
negativeFlag = (long)rangeFlag - 1,
8383
mask = ~negativeFlag;

0 commit comments

Comments
 (0)