Skip to content

Commit 3dba35f

Browse files
Merge branch 'master' into Kyaa-UpdateIssueTemplate
2 parents 8f33529 + baf8adb commit 3dba35f

File tree

642 files changed

+5950
-13720
lines changed

Some content is hidden

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

642 files changed

+5950
-13720
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,4 @@ dotnet_diagnostic.SA1413.severity = none # UseTrailingCommasInMultiLineInitializ
327327
dotnet_diagnostic.SA1314.severity = none # TypeParameterNamesMustBeginWithT: We do have a few templates that don't start with T. We need to double check that changing this is not a breaking change. If not, we can re-enable this.
328328
dotnet_diagnostic.SA1000.severity = none # Hide warnings when using the new() expression from C# 9.
329329
dotnet_diagnostic.SA1313.severity = none # Hide warnings for record parameters.
330-
dotnet_diagnostic.SA1101.severity = none # Hide warnings when accessing properties without "this".
330+
dotnet_diagnostic.SA1101.severity = none # Hide warnings when accessing properties without "this".

GazeInputTest/GazeInputTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
</ItemGroup>
151151
<ItemGroup>
152152
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
153-
<Version>6.2.10</Version>
153+
<Version>6.2.12</Version>
154154
</PackageReference>
155155
<PackageReference Include="StyleCop.Analyzers">
156156
<Version>1.0.2</Version>

Microsoft.Toolkit.HighPerformance/Buffers/Internals/RawObjectMemoryManager{T}.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Runtime.CompilerServices;
1010
using System.Runtime.InteropServices;
1111
using Microsoft.Toolkit.HighPerformance.Extensions;
12+
using Microsoft.Toolkit.HighPerformance.Helpers;
1213

1314
namespace Microsoft.Toolkit.HighPerformance.Buffers.Internals
1415
{
@@ -49,7 +50,7 @@ public RawObjectMemoryManager(object instance, IntPtr offset, int length)
4950
/// <inheritdoc/>
5051
public override Span<T> GetSpan()
5152
{
52-
ref T r0 = ref this.instance.DangerousGetObjectDataReferenceAt<T>(this.offset);
53+
ref T r0 = ref ObjectMarshal.DangerousGetObjectDataReferenceAt<T>(this.instance, this.offset);
5354

5455
return MemoryMarshal.CreateSpan(ref r0, this.length);
5556
}
@@ -68,7 +69,7 @@ public override unsafe MemoryHandle Pin(int elementIndex = 0)
6869
// traditional means (eg. via the implicit T[] array conversion), if T is a
6970
// reference type or a type containing some references.
7071
GCHandle handle = GCHandle.Alloc(this.instance, GCHandleType.Pinned);
71-
ref T r0 = ref this.instance.DangerousGetObjectDataReferenceAt<T>(this.offset);
72+
ref T r0 = ref ObjectMarshal.DangerousGetObjectDataReferenceAt<T>(this.instance, this.offset);
7273
ref T r1 = ref Unsafe.Add(ref r0, (nint)(uint)elementIndex);
7374
void* p = Unsafe.AsPointer(ref r1);
7475

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private MemoryOwner(int start, int length, ArrayPool<T> pool, T[] array)
9191
public static MemoryOwner<T> Empty
9292
{
9393
[MethodImpl(MethodImplOptions.AggressiveInlining)]
94-
get => new MemoryOwner<T>(0, ArrayPool<T>.Shared, AllocationMode.Default);
94+
get => new(0, ArrayPool<T>.Shared, AllocationMode.Default);
9595
}
9696

9797
/// <summary>
@@ -103,7 +103,7 @@ public static MemoryOwner<T> Empty
103103
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
104104
[Pure]
105105
[MethodImpl(MethodImplOptions.AggressiveInlining)]
106-
public static MemoryOwner<T> Allocate(int size) => new MemoryOwner<T>(size, ArrayPool<T>.Shared, AllocationMode.Default);
106+
public static MemoryOwner<T> Allocate(int size) => new(size, ArrayPool<T>.Shared, AllocationMode.Default);
107107

108108
/// <summary>
109109
/// Creates a new <see cref="MemoryOwner{T}"/> instance with the specified parameters.
@@ -115,7 +115,7 @@ public static MemoryOwner<T> Empty
115115
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
116116
[Pure]
117117
[MethodImpl(MethodImplOptions.AggressiveInlining)]
118-
public static MemoryOwner<T> Allocate(int size, ArrayPool<T> pool) => new MemoryOwner<T>(size, pool, AllocationMode.Default);
118+
public static MemoryOwner<T> Allocate(int size, ArrayPool<T> pool) => new(size, pool, AllocationMode.Default);
119119

120120
/// <summary>
121121
/// Creates a new <see cref="MemoryOwner{T}"/> instance with the specified parameters.
@@ -127,7 +127,7 @@ public static MemoryOwner<T> Empty
127127
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
128128
[Pure]
129129
[MethodImpl(MethodImplOptions.AggressiveInlining)]
130-
public static MemoryOwner<T> Allocate(int size, AllocationMode mode) => new MemoryOwner<T>(size, ArrayPool<T>.Shared, mode);
130+
public static MemoryOwner<T> Allocate(int size, AllocationMode mode) => new(size, ArrayPool<T>.Shared, mode);
131131

132132
/// <summary>
133133
/// Creates a new <see cref="MemoryOwner{T}"/> instance with the specified parameters.
@@ -140,7 +140,7 @@ public static MemoryOwner<T> Empty
140140
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
141141
[Pure]
142142
[MethodImpl(MethodImplOptions.AggressiveInlining)]
143-
public static MemoryOwner<T> Allocate(int size, ArrayPool<T> pool, AllocationMode mode) => new MemoryOwner<T>(size, pool, mode);
143+
public static MemoryOwner<T> Allocate(int size, ArrayPool<T> pool, AllocationMode mode) => new(size, pool, mode);
144144

145145
/// <summary>
146146
/// Gets the number of items in the current instance

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private SpanOwner(int length, ArrayPool<T> pool, AllocationMode mode)
8080
public static SpanOwner<T> Empty
8181
{
8282
[MethodImpl(MethodImplOptions.AggressiveInlining)]
83-
get => new SpanOwner<T>(0, ArrayPool<T>.Shared, AllocationMode.Default);
83+
get => new(0, ArrayPool<T>.Shared, AllocationMode.Default);
8484
}
8585

8686
/// <summary>
@@ -92,7 +92,7 @@ public static SpanOwner<T> Empty
9292
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
9393
[Pure]
9494
[MethodImpl(MethodImplOptions.AggressiveInlining)]
95-
public static SpanOwner<T> Allocate(int size) => new SpanOwner<T>(size, ArrayPool<T>.Shared, AllocationMode.Default);
95+
public static SpanOwner<T> Allocate(int size) => new(size, ArrayPool<T>.Shared, AllocationMode.Default);
9696

9797
/// <summary>
9898
/// Creates a new <see cref="SpanOwner{T}"/> instance with the specified parameters.
@@ -104,7 +104,7 @@ public static SpanOwner<T> Empty
104104
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
105105
[Pure]
106106
[MethodImpl(MethodImplOptions.AggressiveInlining)]
107-
public static SpanOwner<T> Allocate(int size, ArrayPool<T> pool) => new SpanOwner<T>(size, pool, AllocationMode.Default);
107+
public static SpanOwner<T> Allocate(int size, ArrayPool<T> pool) => new(size, pool, AllocationMode.Default);
108108

109109
/// <summary>
110110
/// Creates a new <see cref="SpanOwner{T}"/> instance with the specified parameters.
@@ -116,7 +116,7 @@ public static SpanOwner<T> Empty
116116
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
117117
[Pure]
118118
[MethodImpl(MethodImplOptions.AggressiveInlining)]
119-
public static SpanOwner<T> Allocate(int size, AllocationMode mode) => new SpanOwner<T>(size, ArrayPool<T>.Shared, mode);
119+
public static SpanOwner<T> Allocate(int size, AllocationMode mode) => new(size, ArrayPool<T>.Shared, mode);
120120

121121
/// <summary>
122122
/// Creates a new <see cref="SpanOwner{T}"/> instance with the specified parameters.
@@ -129,7 +129,7 @@ public static SpanOwner<T> Empty
129129
/// <remarks>This method is just a proxy for the <see langword="private"/> constructor, for clarity.</remarks>
130130
[Pure]
131131
[MethodImpl(MethodImplOptions.AggressiveInlining)]
132-
public static SpanOwner<T> Allocate(int size, ArrayPool<T> pool, AllocationMode mode) => new SpanOwner<T>(size, pool, mode);
132+
public static SpanOwner<T> Allocate(int size, ArrayPool<T> pool, AllocationMode mode) => new(size, pool, mode);
133133

134134
/// <summary>
135135
/// Gets the number of items in the current instance
@@ -183,7 +183,7 @@ public ref T DangerousGetReference()
183183
[MethodImpl(MethodImplOptions.AggressiveInlining)]
184184
public ArraySegment<T> DangerousGetArray()
185185
{
186-
return new ArraySegment<T>(array!, 0, this.length);
186+
return new(array!, 0, this.length);
187187
}
188188

189189
/// <summary>

Microsoft.Toolkit.HighPerformance/Buffers/StringPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static void FindFactors(int size, int factor, out int x, out int y)
137137
/// process. Since <see cref="StringPool"/> is thread-safe, the shared instance can be used
138138
/// concurrently by multiple threads without the need for manual synchronization.
139139
/// </remarks>
140-
public static StringPool Shared { get; } = new StringPool();
140+
public static StringPool Shared { get; } = new();
141141

142142
/// <summary>
143143
/// Gets the total number of <see cref="string"/> that can be stored in the current instance.

Microsoft.Toolkit.HighPerformance/Enumerables/ReadOnlyRefEnumerable{T}.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#endif
1111
using Microsoft.Toolkit.HighPerformance.Extensions;
1212
using Microsoft.Toolkit.HighPerformance.Helpers.Internals;
13+
using Microsoft.Toolkit.HighPerformance.Memory.Internals;
14+
1315
#if !SPAN_RUNTIME_SUPPORT
1416
using RuntimeHelpers = Microsoft.Toolkit.HighPerformance.Helpers.Internals.RuntimeHelpers;
1517
#endif
@@ -76,6 +78,32 @@ internal ReadOnlyRefEnumerable(in T reference, int length, int step)
7678
this.span = MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(reference), length);
7779
this.step = step;
7880
}
81+
82+
/// <summary>
83+
/// Creates a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct with the specified parameters.
84+
/// </summary>
85+
/// <param name="value">The reference to the first <typeparamref name="T"/> item to map.</param>
86+
/// <param name="length">The number of items in the sequence.</param>
87+
/// <param name="step">The distance between items in the sequence to enumerate.</param>
88+
/// <returns>A <see cref="ReadOnlyRefEnumerable{T}"/> instance with the specified parameters.</returns>
89+
/// <exception cref="ArgumentOutOfRangeException">Thrown when one of the parameters are negative.</exception>
90+
[Pure]
91+
public static ReadOnlyRefEnumerable<T> DangerousCreate(in T value, int length, int step)
92+
{
93+
if (length < 0)
94+
{
95+
ThrowArgumentOutOfRangeExceptionForLength();
96+
}
97+
98+
if (step < 0)
99+
{
100+
ThrowArgumentOutOfRangeExceptionForStep();
101+
}
102+
103+
OverflowHelper.EnsureIsInNativeIntRange(length, 1, step);
104+
105+
return new ReadOnlyRefEnumerable<T>(in value, length, step);
106+
}
79107
#else
80108
/// <summary>
81109
/// Initializes a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct.
@@ -360,6 +388,22 @@ public readonly ref readonly T Current
360388
}
361389
}
362390

391+
/// <summary>
392+
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "length" parameter is invalid.
393+
/// </summary>
394+
private static void ThrowArgumentOutOfRangeExceptionForLength()
395+
{
396+
throw new ArgumentOutOfRangeException("length");
397+
}
398+
399+
/// <summary>
400+
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "step" parameter is invalid.
401+
/// </summary>
402+
private static void ThrowArgumentOutOfRangeExceptionForStep()
403+
{
404+
throw new ArgumentOutOfRangeException("step");
405+
}
406+
363407
/// <summary>
364408
/// Throws an <see cref="ArgumentException"/> when the target span is too short.
365409
/// </summary>

Microsoft.Toolkit.HighPerformance/Enumerables/RefEnumerable{T}.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#endif
1111
using Microsoft.Toolkit.HighPerformance.Extensions;
1212
using Microsoft.Toolkit.HighPerformance.Helpers.Internals;
13-
#if !SPAN_RUNTIME_SUPPORT
13+
#if SPAN_RUNTIME_SUPPORT
14+
using Microsoft.Toolkit.HighPerformance.Memory.Internals;
15+
#else
1416
using RuntimeHelpers = Microsoft.Toolkit.HighPerformance.Helpers.Internals.RuntimeHelpers;
1517
#endif
1618

@@ -64,6 +66,32 @@ internal RefEnumerable(ref T reference, int length, int step)
6466
Span = MemoryMarshal.CreateSpan(ref reference, length);
6567
Step = step;
6668
}
69+
70+
/// <summary>
71+
/// Creates a new instance of the <see cref="RefEnumerable{T}"/> struct with the specified parameters.
72+
/// </summary>
73+
/// <param name="value">The reference to the first <typeparamref name="T"/> item to map.</param>
74+
/// <param name="length">The number of items in the sequence.</param>
75+
/// <param name="step">The distance between items in the sequence to enumerate.</param>
76+
/// <returns>A <see cref="RefEnumerable{T}"/> instance with the specified parameters.</returns>
77+
/// <exception cref="ArgumentOutOfRangeException">Thrown when one of the parameters are negative.</exception>
78+
[Pure]
79+
public static RefEnumerable<T> DangerousCreate(ref T value, int length, int step)
80+
{
81+
if (length < 0)
82+
{
83+
ThrowArgumentOutOfRangeExceptionForLength();
84+
}
85+
86+
if (step < 0)
87+
{
88+
ThrowArgumentOutOfRangeExceptionForStep();
89+
}
90+
91+
OverflowHelper.EnsureIsInNativeIntRange(length, 1, step);
92+
93+
return new RefEnumerable<T>(ref value, length, step);
94+
}
6795
#else
6896
/// <summary>
6997
/// Initializes a new instance of the <see cref="RefEnumerable{T}"/> struct.
@@ -453,6 +481,22 @@ public readonly ref T Current
453481
}
454482
}
455483

484+
/// <summary>
485+
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "length" parameter is invalid.
486+
/// </summary>
487+
private static void ThrowArgumentOutOfRangeExceptionForLength()
488+
{
489+
throw new ArgumentOutOfRangeException("length");
490+
}
491+
492+
/// <summary>
493+
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the "step" parameter is invalid.
494+
/// </summary>
495+
private static void ThrowArgumentOutOfRangeExceptionForStep()
496+
{
497+
throw new ArgumentOutOfRangeException("step");
498+
}
499+
456500
/// <summary>
457501
/// Throws an <see cref="ArgumentException"/> when the target span is too short.
458502
/// </summary>

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
using System.Runtime.InteropServices;
1010
#endif
1111
using Microsoft.Toolkit.HighPerformance.Enumerables;
12+
#if !NETCORE_RUNTIME && !NET5_0
13+
using Microsoft.Toolkit.HighPerformance.Helpers;
14+
#endif
1215
using Microsoft.Toolkit.HighPerformance.Helpers.Internals;
1316
using RuntimeHelpers = Microsoft.Toolkit.HighPerformance.Helpers.Internals.RuntimeHelpers;
1417

@@ -40,7 +43,7 @@ public static ref T DangerousGetReference<T>(this T[] array)
4043
#else
4144
IntPtr offset = RuntimeHelpers.GetArrayDataByteOffset<T>();
4245

43-
return ref array.DangerousGetObjectDataReferenceAt<T>(offset);
46+
return ref ObjectMarshal.DangerousGetObjectDataReferenceAt<T>(array, offset);
4447
#endif
4548
}
4649

@@ -69,7 +72,7 @@ public static ref T DangerousGetReferenceAt<T>(this T[] array, int i)
6972
return ref ri;
7073
#else
7174
IntPtr offset = RuntimeHelpers.GetArrayDataByteOffset<T>();
72-
ref T r0 = ref array.DangerousGetObjectDataReferenceAt<T>(offset);
75+
ref T r0 = ref ObjectMarshal.DangerousGetObjectDataReferenceAt<T>(array, offset);
7376
ref T ri = ref Unsafe.Add(ref r0, (nint)(uint)i);
7477

7578
return ref ri;
@@ -146,7 +149,7 @@ public static int Count<T>(this T[] array, T value)
146149
[MethodImpl(MethodImplOptions.AggressiveInlining)]
147150
public static SpanEnumerable<T> Enumerate<T>(this T[] array)
148151
{
149-
return new SpanEnumerable<T>(array);
152+
return new(array);
150153
}
151154

152155
/// <summary>
@@ -172,7 +175,7 @@ public static SpanEnumerable<T> Enumerate<T>(this T[] array)
172175
public static SpanTokenizer<T> Tokenize<T>(this T[] array, T separator)
173176
where T : IEquatable<T>
174177
{
175-
return new SpanTokenizer<T>(array, separator);
178+
return new(array, separator);
176179
}
177180

178181
/// <summary>

0 commit comments

Comments
 (0)