Skip to content

Commit

Permalink
Add ArgumentNullException.ThrowIfNull
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jan 31, 2023
1 parent 1fd99ef commit a097268
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sandbox/Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#else


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

#endif
Expand Down
20 changes: 20 additions & 0 deletions src/SimdLinq/SimdLinqExtensions.Contains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ public static partial class SimdLinqExtensions
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this byte[] source, byte value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<byte>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<byte> source, byte value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<byte>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -43,12 +45,14 @@ public static unsafe bool Contains(this ReadOnlySpan<byte> source, byte value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this sbyte[] source, sbyte value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<sbyte>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<sbyte> source, sbyte value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<sbyte>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -78,12 +82,14 @@ public static unsafe bool Contains(this ReadOnlySpan<sbyte> source, sbyte value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this short[] source, short value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<short>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<short> source, short value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<short>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -113,12 +119,14 @@ public static unsafe bool Contains(this ReadOnlySpan<short> source, short value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this ushort[] source, ushort value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<ushort>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<ushort> source, ushort value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<ushort>)CollectionsMarshal.AsSpan(source), value);
}

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

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<int> source, int value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<int>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -183,12 +193,14 @@ public static unsafe bool Contains(this ReadOnlySpan<int> source, int value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this uint[] source, uint value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<uint>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<uint> source, uint value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<uint>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -218,12 +230,14 @@ public static unsafe bool Contains(this ReadOnlySpan<uint> source, uint value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this long[] source, long value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<long>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<long> source, long value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<long>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -253,12 +267,14 @@ public static unsafe bool Contains(this ReadOnlySpan<long> source, long value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this ulong[] source, ulong value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<ulong>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<ulong> source, ulong value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<ulong>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -288,12 +304,14 @@ public static unsafe bool Contains(this ReadOnlySpan<ulong> source, ulong value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this float[] source, float value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<float>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<float> source, float value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<float>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down Expand Up @@ -323,12 +341,14 @@ public static unsafe bool Contains(this ReadOnlySpan<float> source, float value)
/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this double[] source, double value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<double>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
public static unsafe bool Contains(this List<double> source, double value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<double>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down
2 changes: 2 additions & 0 deletions src/SimdLinq/SimdLinqExtensions.Contains.tt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public static partial class SimdLinqExtensions
/// <summary>Compute Contains in SIMD.</summary>
<#= signature #>(this <#= type #>[] source, <#= type #> value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore(new ReadOnlySpan<<#= type #>>(source), value);
}

/// <summary>Compute Contains in SIMD.</summary>
<#= signature #>(this List<<#= type #>> source, <#= type #> value)
{
ArgumentNullException.ThrowIfNull(source);
return ContainsCore((ReadOnlySpan<<#= type #>>)CollectionsMarshal.AsSpan(source), value);
}

Expand Down
Loading

0 comments on commit a097268

Please sign in to comment.