Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit a097268

Browse files
committed
Add ArgumentNullException.ThrowIfNull
1 parent 1fd99ef commit a097268

8 files changed

Lines changed: 176 additions & 2 deletions

sandbox/Benchmark/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
#else
3232

33-
34-
System.Linq.Enumerable.Min(Array.Empty<int>());
33+
// _= Enumerable.Max((int[])null!);
34+
//System.Linq.Enumerable.Min(Array.Empty<int>());
3535
//_ = new IntMinBenchmark().SimdLinq();
3636

3737
#endif

src/SimdLinq/SimdLinqExtensions.Contains.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ public static partial class SimdLinqExtensions
88
/// <summary>Compute Contains in SIMD.</summary>
99
public static unsafe bool Contains(this byte[] source, byte value)
1010
{
11+
ArgumentNullException.ThrowIfNull(source);
1112
return ContainsCore(new ReadOnlySpan<byte>(source), value);
1213
}
1314

1415
/// <summary>Compute Contains in SIMD.</summary>
1516
public static unsafe bool Contains(this List<byte> source, byte value)
1617
{
18+
ArgumentNullException.ThrowIfNull(source);
1719
return ContainsCore((ReadOnlySpan<byte>)CollectionsMarshal.AsSpan(source), value);
1820
}
1921

@@ -43,12 +45,14 @@ public static unsafe bool Contains(this ReadOnlySpan<byte> source, byte value)
4345
/// <summary>Compute Contains in SIMD.</summary>
4446
public static unsafe bool Contains(this sbyte[] source, sbyte value)
4547
{
48+
ArgumentNullException.ThrowIfNull(source);
4649
return ContainsCore(new ReadOnlySpan<sbyte>(source), value);
4750
}
4851

4952
/// <summary>Compute Contains in SIMD.</summary>
5053
public static unsafe bool Contains(this List<sbyte> source, sbyte value)
5154
{
55+
ArgumentNullException.ThrowIfNull(source);
5256
return ContainsCore((ReadOnlySpan<sbyte>)CollectionsMarshal.AsSpan(source), value);
5357
}
5458

@@ -78,12 +82,14 @@ public static unsafe bool Contains(this ReadOnlySpan<sbyte> source, sbyte value)
7882
/// <summary>Compute Contains in SIMD.</summary>
7983
public static unsafe bool Contains(this short[] source, short value)
8084
{
85+
ArgumentNullException.ThrowIfNull(source);
8186
return ContainsCore(new ReadOnlySpan<short>(source), value);
8287
}
8388

8489
/// <summary>Compute Contains in SIMD.</summary>
8590
public static unsafe bool Contains(this List<short> source, short value)
8691
{
92+
ArgumentNullException.ThrowIfNull(source);
8793
return ContainsCore((ReadOnlySpan<short>)CollectionsMarshal.AsSpan(source), value);
8894
}
8995

@@ -113,12 +119,14 @@ public static unsafe bool Contains(this ReadOnlySpan<short> source, short value)
113119
/// <summary>Compute Contains in SIMD.</summary>
114120
public static unsafe bool Contains(this ushort[] source, ushort value)
115121
{
122+
ArgumentNullException.ThrowIfNull(source);
116123
return ContainsCore(new ReadOnlySpan<ushort>(source), value);
117124
}
118125

119126
/// <summary>Compute Contains in SIMD.</summary>
120127
public static unsafe bool Contains(this List<ushort> source, ushort value)
121128
{
129+
ArgumentNullException.ThrowIfNull(source);
122130
return ContainsCore((ReadOnlySpan<ushort>)CollectionsMarshal.AsSpan(source), value);
123131
}
124132

@@ -148,12 +156,14 @@ public static unsafe bool Contains(this ReadOnlySpan<ushort> source, ushort valu
148156
/// <summary>Compute Contains in SIMD.</summary>
149157
public static unsafe bool Contains(this int[] source, int value)
150158
{
159+
ArgumentNullException.ThrowIfNull(source);
151160
return ContainsCore(new ReadOnlySpan<int>(source), value);
152161
}
153162

154163
/// <summary>Compute Contains in SIMD.</summary>
155164
public static unsafe bool Contains(this List<int> source, int value)
156165
{
166+
ArgumentNullException.ThrowIfNull(source);
157167
return ContainsCore((ReadOnlySpan<int>)CollectionsMarshal.AsSpan(source), value);
158168
}
159169

@@ -183,12 +193,14 @@ public static unsafe bool Contains(this ReadOnlySpan<int> source, int value)
183193
/// <summary>Compute Contains in SIMD.</summary>
184194
public static unsafe bool Contains(this uint[] source, uint value)
185195
{
196+
ArgumentNullException.ThrowIfNull(source);
186197
return ContainsCore(new ReadOnlySpan<uint>(source), value);
187198
}
188199

189200
/// <summary>Compute Contains in SIMD.</summary>
190201
public static unsafe bool Contains(this List<uint> source, uint value)
191202
{
203+
ArgumentNullException.ThrowIfNull(source);
192204
return ContainsCore((ReadOnlySpan<uint>)CollectionsMarshal.AsSpan(source), value);
193205
}
194206

@@ -218,12 +230,14 @@ public static unsafe bool Contains(this ReadOnlySpan<uint> source, uint value)
218230
/// <summary>Compute Contains in SIMD.</summary>
219231
public static unsafe bool Contains(this long[] source, long value)
220232
{
233+
ArgumentNullException.ThrowIfNull(source);
221234
return ContainsCore(new ReadOnlySpan<long>(source), value);
222235
}
223236

224237
/// <summary>Compute Contains in SIMD.</summary>
225238
public static unsafe bool Contains(this List<long> source, long value)
226239
{
240+
ArgumentNullException.ThrowIfNull(source);
227241
return ContainsCore((ReadOnlySpan<long>)CollectionsMarshal.AsSpan(source), value);
228242
}
229243

@@ -253,12 +267,14 @@ public static unsafe bool Contains(this ReadOnlySpan<long> source, long value)
253267
/// <summary>Compute Contains in SIMD.</summary>
254268
public static unsafe bool Contains(this ulong[] source, ulong value)
255269
{
270+
ArgumentNullException.ThrowIfNull(source);
256271
return ContainsCore(new ReadOnlySpan<ulong>(source), value);
257272
}
258273

259274
/// <summary>Compute Contains in SIMD.</summary>
260275
public static unsafe bool Contains(this List<ulong> source, ulong value)
261276
{
277+
ArgumentNullException.ThrowIfNull(source);
262278
return ContainsCore((ReadOnlySpan<ulong>)CollectionsMarshal.AsSpan(source), value);
263279
}
264280

@@ -288,12 +304,14 @@ public static unsafe bool Contains(this ReadOnlySpan<ulong> source, ulong value)
288304
/// <summary>Compute Contains in SIMD.</summary>
289305
public static unsafe bool Contains(this float[] source, float value)
290306
{
307+
ArgumentNullException.ThrowIfNull(source);
291308
return ContainsCore(new ReadOnlySpan<float>(source), value);
292309
}
293310

294311
/// <summary>Compute Contains in SIMD.</summary>
295312
public static unsafe bool Contains(this List<float> source, float value)
296313
{
314+
ArgumentNullException.ThrowIfNull(source);
297315
return ContainsCore((ReadOnlySpan<float>)CollectionsMarshal.AsSpan(source), value);
298316
}
299317

@@ -323,12 +341,14 @@ public static unsafe bool Contains(this ReadOnlySpan<float> source, float value)
323341
/// <summary>Compute Contains in SIMD.</summary>
324342
public static unsafe bool Contains(this double[] source, double value)
325343
{
344+
ArgumentNullException.ThrowIfNull(source);
326345
return ContainsCore(new ReadOnlySpan<double>(source), value);
327346
}
328347

329348
/// <summary>Compute Contains in SIMD.</summary>
330349
public static unsafe bool Contains(this List<double> source, double value)
331350
{
351+
ArgumentNullException.ThrowIfNull(source);
332352
return ContainsCore((ReadOnlySpan<double>)CollectionsMarshal.AsSpan(source), value);
333353
}
334354

src/SimdLinq/SimdLinqExtensions.Contains.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ public static partial class SimdLinqExtensions
2222
/// <summary>Compute Contains in SIMD.</summary>
2323
<#= signature #>(this <#= type #>[] source, <#= type #> value)
2424
{
25+
ArgumentNullException.ThrowIfNull(source);
2526
return ContainsCore(new ReadOnlySpan<<#= type #>>(source), value);
2627
}
2728

2829
/// <summary>Compute Contains in SIMD.</summary>
2930
<#= signature #>(this List<<#= type #>> source, <#= type #> value)
3031
{
32+
ArgumentNullException.ThrowIfNull(source);
3133
return ContainsCore((ReadOnlySpan<<#= type #>>)CollectionsMarshal.AsSpan(source), value);
3234
}
3335

0 commit comments

Comments
 (0)