Skip to content

Commit 2626c7d

Browse files
committed
Removed unnecessary covariance array checks
1 parent 14f40e2 commit 2626c7d

File tree

2 files changed

+0
-86
lines changed

2 files changed

+0
-86
lines changed

Microsoft.Toolkit.HighPerformance/Memory/ReadOnlyMemory2D{T}.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ public ReadOnlyMemory2D(string text, int offset, int height, int width, int pitc
125125
/// <param name="array">The target array to wrap.</param>
126126
/// <param name="height">The height of the resulting 2D area.</param>
127127
/// <param name="width">The width of each row in the resulting 2D area.</param>
128-
/// <exception cref="ArrayTypeMismatchException">
129-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
130-
/// </exception>
131128
/// <exception cref="ArgumentException">
132129
/// Thrown when either <paramref name="height"/> or <paramref name="width"/> are invalid.
133130
/// </exception>
@@ -145,9 +142,6 @@ public ReadOnlyMemory2D(T[] array, int height, int width)
145142
/// <param name="height">The height of the resulting 2D area.</param>
146143
/// <param name="width">The width of each row in the resulting 2D area.</param>
147144
/// <param name="pitch">The pitch in the resulting 2D area.</param>
148-
/// <exception cref="ArrayTypeMismatchException">
149-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
150-
/// </exception>
151145
/// <exception cref="ArgumentOutOfRangeException">
152146
/// Thrown when one of the input parameters is out of range.
153147
/// </exception>
@@ -156,11 +150,6 @@ public ReadOnlyMemory2D(T[] array, int height, int width)
156150
/// </exception>
157151
public ReadOnlyMemory2D(T[] array, int offset, int height, int width, int pitch)
158152
{
159-
if (array.IsCovariant())
160-
{
161-
ThrowHelper.ThrowArrayTypeMismatchException();
162-
}
163-
164153
if ((uint)offset > (uint)array.Length)
165154
{
166155
ThrowHelper.ThrowArgumentOutOfRangeExceptionForOffset();
@@ -201,9 +190,6 @@ public ReadOnlyMemory2D(T[] array, int offset, int height, int width, int pitch)
201190
/// Initializes a new instance of the <see cref="ReadOnlyMemory2D{T}"/> struct wrapping a 2D array.
202191
/// </summary>
203192
/// <param name="array">The given 2D array to wrap.</param>
204-
/// <exception cref="ArrayTypeMismatchException">
205-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
206-
/// </exception>
207193
public ReadOnlyMemory2D(T[,]? array)
208194
{
209195
if (array is null)
@@ -213,11 +199,6 @@ public ReadOnlyMemory2D(T[,]? array)
213199
return;
214200
}
215201

216-
if (array.IsCovariant())
217-
{
218-
ThrowHelper.ThrowArrayTypeMismatchException();
219-
}
220-
221202
this.instance = array;
222203
this.offset = GetArray2DDataByteOffset<T>();
223204
this.height = array.GetLength(0);
@@ -233,9 +214,6 @@ public ReadOnlyMemory2D(T[,]? array)
233214
/// <param name="column">The target column to map within <paramref name="array"/>.</param>
234215
/// <param name="height">The height to map within <paramref name="array"/>.</param>
235216
/// <param name="width">The width to map within <paramref name="array"/>.</param>
236-
/// <exception cref="ArrayTypeMismatchException">
237-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
238-
/// </exception>
239217
/// <exception cref="ArgumentOutOfRangeException">
240218
/// Thrown when either <paramref name="height"/>, <paramref name="width"/> or <paramref name="height"/>
241219
/// are negative or not within the bounds that are valid for <paramref name="array"/>.
@@ -254,11 +232,6 @@ public ReadOnlyMemory2D(T[,]? array, int row, int column, int height, int width)
254232
return;
255233
}
256234

257-
if (array.IsCovariant())
258-
{
259-
ThrowHelper.ThrowArrayTypeMismatchException();
260-
}
261-
262235
int
263236
rows = array.GetLength(0),
264237
columns = array.GetLength(1);
@@ -295,17 +268,9 @@ public ReadOnlyMemory2D(T[,]? array, int row, int column, int height, int width)
295268
/// </summary>
296269
/// <param name="array">The given 3D array to wrap.</param>
297270
/// <param name="depth">The target layer to map within <paramref name="array"/>.</param>
298-
/// <exception cref="ArrayTypeMismatchException">
299-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
300-
/// </exception>
301271
/// <exception cref="ArgumentOutOfRangeException">Thrown when a parameter is invalid.</exception>
302272
public ReadOnlyMemory2D(T[,,] array, int depth)
303273
{
304-
if (array.IsCovariant())
305-
{
306-
ThrowHelper.ThrowArrayTypeMismatchException();
307-
}
308-
309274
if ((uint)depth >= (uint)array.GetLength(0))
310275
{
311276
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();
@@ -327,17 +292,9 @@ public ReadOnlyMemory2D(T[,,] array, int depth)
327292
/// <param name="column">The target column to map within <paramref name="array"/>.</param>
328293
/// <param name="height">The height to map within <paramref name="array"/>.</param>
329294
/// <param name="width">The width to map within <paramref name="array"/>.</param>
330-
/// <exception cref="ArrayTypeMismatchException">
331-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
332-
/// </exception>
333295
/// <exception cref="ArgumentOutOfRangeException">Thrown when a parameter is invalid.</exception>
334296
public ReadOnlyMemory2D(T[,,] array, int depth, int row, int column, int height, int width)
335297
{
336-
if (array.IsCovariant())
337-
{
338-
ThrowHelper.ThrowArrayTypeMismatchException();
339-
}
340-
341298
if ((uint)depth >= (uint)array.GetLength(0))
342299
{
343300
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();

Microsoft.Toolkit.HighPerformance/Memory/ReadOnlySpan2D{T}.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ internal ReadOnlySpan2D(object? instance, IntPtr offset, int height, int width,
143143
/// <param name="array">The target array to wrap.</param>
144144
/// <param name="height">The height of the resulting 2D area.</param>
145145
/// <param name="width">The width of each row in the resulting 2D area.</param>
146-
/// <exception cref="ArrayTypeMismatchException">
147-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
148-
/// </exception>
149146
/// <exception cref="ArgumentException">
150147
/// Thrown when either <paramref name="height"/> or <paramref name="width"/> are invalid.
151148
/// </exception>
@@ -163,9 +160,6 @@ public ReadOnlySpan2D(T[] array, int height, int width)
163160
/// <param name="height">The height of the resulting 2D area.</param>
164161
/// <param name="width">The width of each row in the resulting 2D area.</param>
165162
/// <param name="pitch">The pitch in the resulting 2D area.</param>
166-
/// <exception cref="ArrayTypeMismatchException">
167-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
168-
/// </exception>
169163
/// <exception cref="ArgumentOutOfRangeException">
170164
/// Thrown when one of the input parameters is out of range.
171165
/// </exception>
@@ -174,11 +168,6 @@ public ReadOnlySpan2D(T[] array, int height, int width)
174168
/// </exception>
175169
public ReadOnlySpan2D(T[] array, int offset, int height, int width, int pitch)
176170
{
177-
if (array.IsCovariant())
178-
{
179-
ThrowHelper.ThrowArrayTypeMismatchException();
180-
}
181-
182171
if ((uint)offset > (uint)array.Length)
183172
{
184173
ThrowHelper.ThrowArgumentOutOfRangeExceptionForOffset();
@@ -230,9 +219,6 @@ public ReadOnlySpan2D(T[] array, int offset, int height, int width, int pitch)
230219
/// Initializes a new instance of the <see cref="ReadOnlySpan2D{T}"/> struct wrapping a 2D array.
231220
/// </summary>
232221
/// <param name="array">The given 2D array to wrap.</param>
233-
/// <exception cref="ArrayTypeMismatchException">
234-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
235-
/// </exception>
236222
public ReadOnlySpan2D(T[,]? array)
237223
{
238224
if (array is null)
@@ -242,11 +228,6 @@ public ReadOnlySpan2D(T[,]? array)
242228
return;
243229
}
244230

245-
if (array.IsCovariant())
246-
{
247-
ThrowHelper.ThrowArrayTypeMismatchException();
248-
}
249-
250231
#if SPAN_RUNTIME_SUPPORT
251232
this.span = MemoryMarshal.CreateReadOnlySpan(ref array.DangerousGetReference(), array.GetLength(0));
252233
#else
@@ -265,9 +246,6 @@ public ReadOnlySpan2D(T[,]? array)
265246
/// <param name="column">The target column to map within <paramref name="array"/>.</param>
266247
/// <param name="height">The height to map within <paramref name="array"/>.</param>
267248
/// <param name="width">The width to map within <paramref name="array"/>.</param>
268-
/// <exception cref="ArrayTypeMismatchException">
269-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
270-
/// </exception>
271249
/// <exception cref="ArgumentOutOfRangeException">
272250
/// Thrown when either <paramref name="height"/>, <paramref name="width"/> or <paramref name="height"/>
273251
/// are negative or not within the bounds that are valid for <paramref name="array"/>.
@@ -286,11 +264,6 @@ public ReadOnlySpan2D(T[,]? array, int row, int column, int height, int width)
286264
return;
287265
}
288266

289-
if (array.IsCovariant())
290-
{
291-
ThrowHelper.ThrowArrayTypeMismatchException();
292-
}
293-
294267
int
295268
rows = array.GetLength(0),
296269
columns = array.GetLength(1);
@@ -331,17 +304,9 @@ public ReadOnlySpan2D(T[,]? array, int row, int column, int height, int width)
331304
/// </summary>
332305
/// <param name="array">The given 3D array to wrap.</param>
333306
/// <param name="depth">The target layer to map within <paramref name="array"/>.</param>
334-
/// <exception cref="ArrayTypeMismatchException">
335-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
336-
/// </exception>
337307
/// <exception cref="ArgumentOutOfRangeException">Thrown when a parameter is invalid.</exception>
338308
public ReadOnlySpan2D(T[,,] array, int depth)
339309
{
340-
if (array.IsCovariant())
341-
{
342-
ThrowHelper.ThrowArrayTypeMismatchException();
343-
}
344-
345310
if ((uint)depth >= (uint)array.GetLength(0))
346311
{
347312
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();
@@ -366,17 +331,9 @@ public ReadOnlySpan2D(T[,,] array, int depth)
366331
/// <param name="column">The target column to map within <paramref name="array"/>.</param>
367332
/// <param name="height">The height to map within <paramref name="array"/>.</param>
368333
/// <param name="width">The width to map within <paramref name="array"/>.</param>
369-
/// <exception cref="ArrayTypeMismatchException">
370-
/// Thrown when <paramref name="array"/> doesn't match <typeparamref name="T"/>.
371-
/// </exception>
372334
/// <exception cref="ArgumentOutOfRangeException">Thrown when a parameter is invalid.</exception>
373335
public ReadOnlySpan2D(T[,,] array, int depth, int row, int column, int height, int width)
374336
{
375-
if (array.IsCovariant())
376-
{
377-
ThrowHelper.ThrowArrayTypeMismatchException();
378-
}
379-
380337
if ((uint)depth >= (uint)array.GetLength(0))
381338
{
382339
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();

0 commit comments

Comments
 (0)