Skip to content

Commit 5bf1787

Browse files
authored
Merge branch 'master' into wrapPanel.verticalAlignment
2 parents cf81a75 + 49a88c7 commit 5bf1787

File tree

176 files changed

+3212
-2511
lines changed

Some content is hidden

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

176 files changed

+3212
-2511
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
1515
<IsUwpProject Condition="'$(IsDesignProject)' != 'true'">$(MSBuildProjectName.Contains('Uwp'))</IsUwpProject>
1616
<IsSampleProject>$(MSBuildProjectName.Contains('Sample'))</IsSampleProject>
17-
<DefaultTargetPlatformVersion>18362</DefaultTargetPlatformVersion>
18-
<DefaultTargetPlatformMinVersion>16299</DefaultTargetPlatformMinVersion>
17+
<DefaultTargetPlatformVersion>19041</DefaultTargetPlatformVersion>
18+
<DefaultTargetPlatformMinVersion>17763</DefaultTargetPlatformMinVersion>
1919
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\nupkg</PackageOutputPath>
2020
</PropertyGroup>
2121

Directory.Build.targets

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<Choose>
3-
<When Condition="'$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'uap10.0.16299' or '$(TargetFramework)' == 'native' or '$(TargetFramework)' == 'net461'">
3+
<When Condition="'$(TargetFramework)' == 'uap10.0' or '$(TargetFramework)' == 'uap10.0.17763' or '$(TargetFramework)' == 'native' or '$(TargetFramework)' == 'net461'">
44
<!-- UAP versions for uap10.0 where TPMV isn't implied -->
55
<PropertyGroup>
66
<TargetPlatformVersion>10.0.$(DefaultTargetPlatformVersion).0</TargetPlatformVersion>
@@ -15,9 +15,6 @@
1515
<SDKReference Condition="'$(UseWindowsDesktopSdk)' == 'true' " Include="WindowsDesktop, Version=$(TargetPlatformVersion)">
1616
<Name>Windows Desktop Extensions for the UWP</Name>
1717
</SDKReference>
18-
<SDKReference Condition="'$(UseWindowsMobileSdk)' == 'true' " Include="WindowsMobile, Version=$(TargetPlatformVersion)">
19-
<Name>Windows Mobile Extensions for the UWP</Name>
20-
</SDKReference>
2118
</ItemGroup>
2219
</When>
2320
</Choose>

GazeInputTest/GazeInputTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<AssemblyName>GazeInputTest</AssemblyName>
1212
<DefaultLanguage>en-US</DefaultLanguage>
1313
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
14-
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
14+
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.19041.0</TargetPlatformVersion>
1515
<TargetPlatformMinVersion>10.0.17134.0</TargetPlatformMinVersion>
1616
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
1717
<FileAlignment>512</FileAlignment>

Microsoft.Toolkit.HighPerformance/Box{T}.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static bool TryGetFrom(object obj, [NotNullWhen(true)] out Box<T>? box)
125125
[MethodImpl(MethodImplOptions.AggressiveInlining)]
126126
public static implicit operator T(Box<T> box)
127127
{
128-
return Unsafe.Unbox<T>(box);
128+
return (T)(object)box;
129129
}
130130

131131
/// <summary>
@@ -180,7 +180,6 @@ public override int GetHashCode()
180180
/// <summary>
181181
/// Throws an <see cref="InvalidCastException"/> when a cast from an invalid <see cref="object"/> is attempted.
182182
/// </summary>
183-
[MethodImpl(MethodImplOptions.NoInlining)]
184183
private static void ThrowInvalidCastExceptionForGetFrom()
185184
{
186185
throw new InvalidCastException($"Can't cast the input object to the type Box<{typeof(T)}>");

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

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
3333
/// </summary>
3434
private const int DefaultInitialBufferSize = 256;
3535

36+
/// <summary>
37+
/// The <see cref="ArrayPool{T}"/> instance used to rent <see cref="array"/>.
38+
/// </summary>
39+
private readonly ArrayPool<T> pool;
40+
3641
/// <summary>
3742
/// The underlying <typeparamref name="T"/> array.
3843
/// </summary>
@@ -49,36 +54,52 @@ public sealed class ArrayPoolBufferWriter<T> : IBuffer<T>, IMemoryOwner<T>
4954
/// Initializes a new instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
5055
/// </summary>
5156
public ArrayPoolBufferWriter()
57+
: this(ArrayPool<T>.Shared, DefaultInitialBufferSize)
58+
{
59+
}
60+
61+
/// <summary>
62+
/// Initializes a new instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
63+
/// </summary>
64+
/// <param name="pool">The <see cref="ArrayPool{T}"/> instance to use.</param>
65+
public ArrayPoolBufferWriter(ArrayPool<T> pool)
66+
: this(pool, DefaultInitialBufferSize)
5267
{
53-
// Since we're using pooled arrays, we can rent the buffer with the
54-
// default size immediately, we don't need to use lazy initialization
55-
// to save unnecessary memory allocations in this case.
56-
this.array = ArrayPool<T>.Shared.Rent(DefaultInitialBufferSize);
57-
this.index = 0;
5868
}
5969

6070
/// <summary>
6171
/// Initializes a new instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
6272
/// </summary>
6373
/// <param name="initialCapacity">The minimum capacity with which to initialize the underlying buffer.</param>
64-
/// <exception cref="ArgumentException">
65-
/// Thrown when <paramref name="initialCapacity"/> is not positive (i.e. less than or equal to 0).
66-
/// </exception>
74+
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="initialCapacity"/> is not valid.</exception>
6775
public ArrayPoolBufferWriter(int initialCapacity)
76+
: this(ArrayPool<T>.Shared, initialCapacity)
6877
{
69-
if (initialCapacity <= 0)
70-
{
71-
ThrowArgumentOutOfRangeExceptionForInitialCapacity();
72-
}
78+
}
7379

74-
this.array = ArrayPool<T>.Shared.Rent(initialCapacity);
80+
/// <summary>
81+
/// Initializes a new instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
82+
/// </summary>
83+
/// <param name="pool">The <see cref="ArrayPool{T}"/> instance to use.</param>
84+
/// <param name="initialCapacity">The minimum capacity with which to initialize the underlying buffer.</param>
85+
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="initialCapacity"/> is not valid.</exception>
86+
public ArrayPoolBufferWriter(ArrayPool<T> pool, int initialCapacity)
87+
{
88+
// Since we're using pooled arrays, we can rent the buffer with the
89+
// default size immediately, we don't need to use lazy initialization
90+
// to save unnecessary memory allocations in this case.
91+
// Additionally, we don't need to manually throw the exception if
92+
// the requested size is not valid, as that'll be thrown automatically
93+
// by the array pool in use when we try to rent an array with that size.
94+
this.pool = pool;
95+
this.array = pool.Rent(initialCapacity);
7596
this.index = 0;
7697
}
7798

7899
/// <summary>
79100
/// Finalizes an instance of the <see cref="ArrayPoolBufferWriter{T}"/> class.
80101
/// </summary>
81-
~ArrayPoolBufferWriter() => this.Dispose();
102+
~ArrayPoolBufferWriter() => Dispose();
82103

83104
/// <inheritdoc/>
84105
Memory<T> IMemoryOwner<T>.Memory
@@ -182,6 +203,7 @@ public void Clear()
182203
}
183204

184205
array.AsSpan(0, this.index).Clear();
206+
185207
this.index = 0;
186208
}
187209

@@ -250,7 +272,7 @@ private void CheckAndResizeBuffer(int sizeHint)
250272
{
251273
int minimumSize = this.index + sizeHint;
252274

253-
ArrayPool<T>.Shared.Resize(ref this.array, minimumSize);
275+
this.pool.Resize(ref this.array, minimumSize);
254276
}
255277
}
256278

@@ -268,7 +290,7 @@ public void Dispose()
268290

269291
this.array = null;
270292

271-
ArrayPool<T>.Shared.Return(array);
293+
this.pool.Return(array);
272294
}
273295

274296
/// <inheritdoc/>
@@ -286,19 +308,9 @@ public override string ToString()
286308
return $"Microsoft.Toolkit.HighPerformance.Buffers.ArrayPoolBufferWriter<{typeof(T)}>[{this.index}]";
287309
}
288310

289-
/// <summary>
290-
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the initial capacity is invalid.
291-
/// </summary>
292-
[MethodImpl(MethodImplOptions.NoInlining)]
293-
private static void ThrowArgumentOutOfRangeExceptionForInitialCapacity()
294-
{
295-
throw new ArgumentOutOfRangeException("initialCapacity", "The initial capacity must be a positive value");
296-
}
297-
298311
/// <summary>
299312
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
300313
/// </summary>
301-
[MethodImpl(MethodImplOptions.NoInlining)]
302314
private static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
303315
{
304316
throw new ArgumentOutOfRangeException("count", "The count can't be a negative value");
@@ -307,7 +319,6 @@ private static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
307319
/// <summary>
308320
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the size hint is negative.
309321
/// </summary>
310-
[MethodImpl(MethodImplOptions.NoInlining)]
311322
private static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
312323
{
313324
throw new ArgumentOutOfRangeException("sizeHint", "The size hint can't be a negative value");
@@ -316,7 +327,6 @@ private static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
316327
/// <summary>
317328
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
318329
/// </summary>
319-
[MethodImpl(MethodImplOptions.NoInlining)]
320330
private static void ThrowArgumentExceptionForAdvancedTooFar()
321331
{
322332
throw new ArgumentException("The buffer writer has advanced too far");
@@ -325,7 +335,6 @@ private static void ThrowArgumentExceptionForAdvancedTooFar()
325335
/// <summary>
326336
/// Throws an <see cref="ObjectDisposedException"/> when <see cref="array"/> is <see langword="null"/>.
327337
/// </summary>
328-
[MethodImpl(MethodImplOptions.NoInlining)]
329338
private static void ThrowObjectDisposedException()
330339
{
331340
throw new ObjectDisposedException("The current buffer has already been disposed");

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ public void Advance(int count)
106106
/// <inheritdoc/>
107107
public Memory<T> GetMemory(int sizeHint = 0)
108108
{
109-
this.ValidateSizeHint(sizeHint);
109+
ValidateSizeHint(sizeHint);
110110

111111
return this.memory.Slice(this.index);
112112
}
113113

114114
/// <inheritdoc/>
115115
public Span<T> GetSpan(int sizeHint = 0)
116116
{
117-
this.ValidateSizeHint(sizeHint);
117+
ValidateSizeHint(sizeHint);
118118

119119
return this.memory.Slice(this.index).Span;
120120
}
@@ -159,7 +159,6 @@ public override string ToString()
159159
/// <summary>
160160
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
161161
/// </summary>
162-
[MethodImpl(MethodImplOptions.NoInlining)]
163162
private static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
164163
{
165164
throw new ArgumentOutOfRangeException("count", "The count can't be a negative value");
@@ -168,7 +167,6 @@ private static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
168167
/// <summary>
169168
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the size hint is negative.
170169
/// </summary>
171-
[MethodImpl(MethodImplOptions.NoInlining)]
172170
private static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
173171
{
174172
throw new ArgumentOutOfRangeException("sizeHint", "The size hint can't be a negative value");
@@ -177,7 +175,6 @@ private static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
177175
/// <summary>
178176
/// Throws an <see cref="ArgumentOutOfRangeException"/> when the requested count is negative.
179177
/// </summary>
180-
[MethodImpl(MethodImplOptions.NoInlining)]
181178
private static void ThrowArgumentExceptionForAdvancedTooFar()
182179
{
183180
throw new ArgumentException("The buffer writer has advanced too far");
@@ -186,7 +183,6 @@ private static void ThrowArgumentExceptionForAdvancedTooFar()
186183
/// <summary>
187184
/// Throws an <see cref="ArgumentException"/> when the requested size exceeds the capacity.
188185
/// </summary>
189-
[MethodImpl(MethodImplOptions.NoInlining)]
190186
private static void ThrowArgumentExceptionForCapacityExceeded()
191187
{
192188
throw new ArgumentException("The buffer writer doesn't have enough capacity left");

0 commit comments

Comments
 (0)