-
Notifications
You must be signed in to change notification settings - Fork 1.4k
.NET 5 target for Toolkit and HighPerformance packages #3356
Changes from all commits
c6d95bd
2815e8f
3940fe0
bb52951
2e53d7c
7e48bc1
d29381f
aabf73d
d410686
e79f020
631d8f7
5739c7f
35267b1
d7de21b
f2cb8a6
20f211a
50bd227
d3f9e56
ef08f54
81a2380
05b08a9
c177ecf
0ebe685
e6f88c8
bb46627
7312d78
a178cc1
e3d533a
12f66e9
cd3c560
5534643
3f752a8
26f4907
a3b0ba6
c85af73
9322de6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #if !NET5_0 | ||
|
|
||
| namespace System.Runtime.CompilerServices | ||
| { | ||
| /// <summary> | ||
| /// Used to indicate to the compiler that the <c>.locals init</c> flag should not be set in method headers. | ||
| /// </summary> | ||
| /// <remarks>Internal copy of the .NET 5 attribute.</remarks> | ||
| [AttributeUsage( | ||
| AttributeTargets.Module | | ||
| AttributeTargets.Class | | ||
| AttributeTargets.Struct | | ||
| AttributeTargets.Interface | | ||
| AttributeTargets.Constructor | | ||
| AttributeTargets.Method | | ||
| AttributeTargets.Property | | ||
| AttributeTargets.Event, | ||
| Inherited = false)] | ||
| internal sealed class SkipLocalsInitAttribute : Attribute | ||
| { | ||
| } | ||
| } | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,9 @@ public static class BoolExtensions | |
| /// <remarks>This method does not contain branching instructions.</remarks> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static byte ToByte(this bool flag) | ||
| public static unsafe byte ToByte(this bool flag) | ||
| { | ||
| return Unsafe.As<bool, byte>(ref flag); | ||
| return *(byte*)&flag; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New optimization from .NET 5 compiler???
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahahah nope, just good old C# trickery 😄 |
||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -35,9 +35,9 @@ public static byte ToByte(this bool flag) | |
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| [Obsolete("Use ToByte instead.")] | ||
| public static int ToInt(this bool flag) | ||
| public static unsafe int ToInt(this bool flag) | ||
| { | ||
| return Unsafe.As<bool, byte>(ref flag); | ||
| return *(byte*)&flag; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -56,9 +56,9 @@ public static int ToInt(this bool flag) | |
| /// </remarks> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static int ToBitwiseMask32(this bool flag) | ||
| public static unsafe int ToBitwiseMask32(this bool flag) | ||
| { | ||
| byte rangeFlag = Unsafe.As<bool, byte>(ref flag); | ||
| byte rangeFlag = *(byte*)&flag; | ||
| int | ||
| negativeFlag = rangeFlag - 1, | ||
| mask = ~negativeFlag; | ||
|
|
@@ -75,9 +75,9 @@ public static int ToBitwiseMask32(this bool flag) | |
| /// <remarks>This method does not contain branching instructions. See additional note in <see cref="ToBitwiseMask32"/>.</remarks> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static long ToBitwiseMask64(this bool flag) | ||
| public static unsafe long ToBitwiseMask64(this bool flag) | ||
| { | ||
| byte rangeFlag = Unsafe.As<bool, byte>(ref flag); | ||
| byte rangeFlag = *(byte*)&flag; | ||
| long | ||
| negativeFlag = (long)rangeFlag - 1, | ||
| mask = ~negativeFlag; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| #if NET5_0 | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.Contracts; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace Microsoft.Toolkit.HighPerformance.Extensions | ||
| { | ||
| /// <summary> | ||
| /// Helpers for working with the <see cref="List{T}"/> type. | ||
| /// </summary> | ||
| public static class ListExtensions | ||
| { | ||
| /// <summary> | ||
| /// Creates a new <see cref="Span{T}"/> over an input <see cref="List{T}"/> instance. | ||
| /// </summary> | ||
| /// <typeparam name="T">The type of elements in the input <see cref="List{T}"/> instance.</typeparam> | ||
| /// <param name="list">The input <see cref="List{T}"/> instance.</param> | ||
| /// <returns>A <see cref="Span{T}"/> instance with the values of <paramref name="list"/>.</returns> | ||
| /// <remarks> | ||
| /// Note that the returned <see cref="Span{T}"/> is only guaranteed to be valid as long as the items within | ||
| /// <paramref name="list"/> are not modified. Doing so might cause the <see cref="List{T}"/> to swap its | ||
| /// internal buffer, causing the returned <see cref="Span{T}"/> to become out of date. That means that in this | ||
| /// scenario, the <see cref="Span{T}"/> would end up wrapping an array no longer in use. Always make sure to use | ||
| /// the returned <see cref="Span{T}"/> while the target <see cref="List{T}"/> is not modified. | ||
| /// </remarks> | ||
| [Pure] | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static Span<T> AsSpan<T>(this List<T>? list) | ||
| { | ||
| return CollectionsMarshal.AsSpan(list); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this
publicin 6.1? This is just an internal helper, eh?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thankfully not 🤣
This is just an internal helper that I added in #3353, but that accidentally left out as public there. I think it was because this was initially in an internal throw helper class (so the method was public), then I moved it here and forgot to change the accessibility modifier. Really glad I spotted it in time for 7.0 😅