Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace CommunityToolkit.HighPerformance.Enumerables;
/// <typeparam name="T">The type of items to enumerate.</typeparam>
public readonly ref struct ReadOnlyRefEnumerable<T>
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// The <typeparamref name="T"/> reference for the <see cref="ReadOnlyRefEnumerable{T}"/> instance.
/// </summary>
Expand Down Expand Up @@ -61,7 +61,7 @@ public readonly ref struct ReadOnlyRefEnumerable<T>
private readonly int step;

#if NETSTANDARD2_1_OR_GREATER
#if !NET7_0_OR_GREATER
#if !NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct.
/// </summary>
Expand All @@ -70,7 +70,7 @@ public readonly ref struct ReadOnlyRefEnumerable<T>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private ReadOnlyRefEnumerable(ReadOnlySpan<T> span, int step)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
this.reference = ref MemoryMarshal.GetReference(span);
this.length = span.Length;
#else
Expand All @@ -89,7 +89,7 @@ private ReadOnlyRefEnumerable(ReadOnlySpan<T> span, int step)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ReadOnlyRefEnumerable(in T reference, int length, int step)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
this.reference = ref reference;
this.length = length;
this.step = step;
Expand Down Expand Up @@ -147,7 +147,7 @@ internal ReadOnlyRefEnumerable(object? instance, IntPtr offset, int length, int
public int Length
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
get => this.length;
#elif NETSTANDARD2_1_OR_GREATER
get => this.span.Length;
Expand All @@ -174,7 +174,7 @@ public ref readonly T this[int index]
ThrowHelper.ThrowIndexOutOfRangeException();
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
ref T r0 = ref Unsafe.AsRef(in this.reference);
#elif NETSTANDARD2_1_OR_GREATER
ref T r0 = ref MemoryMarshal.GetReference(this.span);
Expand Down Expand Up @@ -208,7 +208,7 @@ public ref readonly T this[Index index]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Enumerator GetEnumerator()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return new(in this.reference, this.length, this.step);
#elif NETSTANDARD2_1_OR_GREATER
return new(this.span, this.step);
Expand All @@ -226,7 +226,7 @@ public Enumerator GetEnumerator()
/// </exception>
public void CopyTo(RefEnumerable<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (this.step == 1)
{
destination.CopyFrom(MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in this.reference), this.length));
Expand Down Expand Up @@ -286,7 +286,7 @@ public void CopyTo(RefEnumerable<T> destination)
/// <returns>Whether or not the operation was successful.</returns>
public bool TryCopyTo(RefEnumerable<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int sourceLength = this.length;
int destinationLength = destination.Length;
#elif NETSTANDARD2_1_OR_GREATER
Expand Down Expand Up @@ -316,7 +316,7 @@ public bool TryCopyTo(RefEnumerable<T> destination)
/// </exception>
public void CopyTo(Span<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (this.step == 1)
{
MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in this.reference), this.length).CopyTo(destination);
Expand Down Expand Up @@ -357,7 +357,7 @@ public void CopyTo(Span<T> destination)
/// <returns>Whether or not the operation was successful.</returns>
public bool TryCopyTo(Span<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int length = this.length;
#elif NETSTANDARD2_1_OR_GREATER
int length = this.span.Length;
Expand All @@ -378,7 +378,7 @@ public bool TryCopyTo(Span<T> destination)
/// <inheritdoc cref="RefEnumerable{T}.ToArray"/>
public T[] ToArray()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int length = this.length;
#elif NETSTANDARD2_1_OR_GREATER
int length = this.span.Length;
Expand Down Expand Up @@ -406,7 +406,7 @@ public T[] ToArray()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlyRefEnumerable<T>(RefEnumerable<T> enumerable)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return new(in enumerable.Reference, enumerable.Length, enumerable.Step);
#elif NETSTANDARD2_1_OR_GREATER
return new(enumerable.Span, enumerable.Step);
Expand All @@ -420,7 +420,7 @@ public static implicit operator ReadOnlyRefEnumerable<T>(RefEnumerable<T> enumer
/// </summary>
public ref struct Enumerator
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <inheritdoc cref="ReadOnlyRefEnumerable{T}.reference"/>
private readonly ref readonly T reference;

Expand Down Expand Up @@ -448,7 +448,7 @@ public ref struct Enumerator
/// </summary>
private int position;

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="Enumerator"/> struct.
/// </summary>
Expand Down Expand Up @@ -499,7 +499,7 @@ internal Enumerator(object? instance, IntPtr offset, int length, int step)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return ++this.position < this.length;
#elif NETSTANDARD2_1_OR_GREATER
return ++this.position < this.span.Length;
Expand All @@ -514,7 +514,7 @@ public readonly ref readonly T Current
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
ref T r0 = ref Unsafe.AsRef(in this.reference);
#elif NETSTANDARD2_1_OR_GREATER
ref T r0 = ref this.span.DangerousGetReference();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public readonly Item Current
[EditorBrowsable(EditorBrowsableState.Never)]
public readonly ref struct Item
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// The <typeparamref name="T"/> reference for the <see cref="Item"/> instance.
/// </summary>
Expand All @@ -107,7 +107,7 @@ public readonly ref struct Item
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Item(ref T value, int index)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
this.reference = ref value;
this.index = index;
#else
Expand Down Expand Up @@ -141,7 +141,7 @@ public ref readonly T Value
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return ref this.reference;
#elif NETSTANDARD2_1_OR_GREATER
return ref MemoryMarshal.GetReference(this.span);
Expand All @@ -162,7 +162,7 @@ public int Index
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return this.index;
#elif NETSTANDARD2_1_OR_GREATER
return this.span.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace CommunityToolkit.HighPerformance.Enumerables;
/// <typeparam name="T">The type of items to enumerate.</typeparam>
public readonly ref struct RefEnumerable<T>
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// The <typeparamref name="T"/> reference for the <see cref="RefEnumerable{T}"/> instance.
/// </summary>
Expand Down Expand Up @@ -65,7 +65,7 @@ public readonly ref struct RefEnumerable<T>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal RefEnumerable(ref T reference, int length, int step)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
this.Reference = ref reference;
this.length = length;
#else
Expand Down Expand Up @@ -123,7 +123,7 @@ internal RefEnumerable(object? instance, IntPtr offset, int length, int step)
public int Length
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
get => this.length;
#elif NETSTANDARD2_1_OR_GREATER
get => this.Span.Length;
Expand All @@ -150,7 +150,7 @@ public ref T this[int index]
ThrowHelper.ThrowIndexOutOfRangeException();
}

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
ref T r0 = ref this.Reference;
#elif NETSTANDARD2_1_OR_GREATER
ref T r0 = ref MemoryMarshal.GetReference(this.Span);
Expand Down Expand Up @@ -184,7 +184,7 @@ public ref T this[Index index]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Enumerator GetEnumerator()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return new(ref this.Reference, this.length, this.Step);
#elif NETSTANDARD2_1_OR_GREATER
return new(this.Span, this.Step);
Expand All @@ -198,7 +198,7 @@ public Enumerator GetEnumerator()
/// </summary>
public void Clear()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
// Fast path for contiguous items
if (this.Step == 1)
{
Expand Down Expand Up @@ -236,7 +236,7 @@ public void Clear()
/// </exception>
public void CopyTo(RefEnumerable<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (this.Step == 1)
{
destination.CopyFrom(MemoryMarshal.CreateReadOnlySpan(ref this.Reference, this.length));
Expand Down Expand Up @@ -296,7 +296,7 @@ public void CopyTo(RefEnumerable<T> destination)
/// <returns>Whether or not the operation was successful.</returns>
public bool TryCopyTo(RefEnumerable<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int sourceLength = this.length;
int destinationLength = destination.length;
#elif NETSTANDARD2_1_OR_GREATER
Expand Down Expand Up @@ -326,7 +326,7 @@ public bool TryCopyTo(RefEnumerable<T> destination)
/// </exception>
public void CopyTo(Span<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (this.Step == 1)
{
MemoryMarshal.CreateReadOnlySpan(ref this.Reference, this.length).CopyTo(destination);
Expand Down Expand Up @@ -367,7 +367,7 @@ public void CopyTo(Span<T> destination)
/// <returns>Whether or not the operation was successful.</returns>
public bool TryCopyTo(Span<T> destination)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int length = this.length;
#elif NETSTANDARD2_1_OR_GREATER
int length = this.Span.Length;
Expand All @@ -394,7 +394,7 @@ public bool TryCopyTo(Span<T> destination)
/// </exception>
internal void CopyFrom(ReadOnlySpan<T> source)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (this.Step == 1)
{
source.CopyTo(MemoryMarshal.CreateSpan(ref this.Reference, this.length));
Expand Down Expand Up @@ -436,7 +436,7 @@ internal void CopyFrom(ReadOnlySpan<T> source)
/// <returns>Whether or not the operation was successful.</returns>
public bool TryCopyFrom(ReadOnlySpan<T> source)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int length = this.length;
#elif NETSTANDARD2_1_OR_GREATER
int length = this.Span.Length;
Expand All @@ -460,7 +460,7 @@ public bool TryCopyFrom(ReadOnlySpan<T> source)
/// <param name="value">The value to assign to each element of the <see cref="RefEnumerable{T}"/> instance.</param>
public void Fill(T value)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
if (this.Step == 1)
{
MemoryMarshal.CreateSpan(ref this.Reference, this.length).Fill(value);
Expand Down Expand Up @@ -498,7 +498,7 @@ public void Fill(T value)
/// </remarks>
public T[] ToArray()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
int length = this.length;
#elif NETSTANDARD2_1_OR_GREATER
int length = this.Span.Length;
Expand All @@ -524,7 +524,7 @@ public T[] ToArray()
/// </summary>
public ref struct Enumerator
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <inheritdoc cref="RefEnumerable{T}.Reference"/>
private readonly ref T reference;

Expand Down Expand Up @@ -552,7 +552,7 @@ public ref struct Enumerator
/// </summary>
private int position;

#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// Initializes a new instance of the <see cref="Enumerator"/> struct.
/// </summary>
Expand Down Expand Up @@ -603,7 +603,7 @@ internal Enumerator(object? instance, IntPtr offset, int length, int step)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext()
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return ++this.position < this.length;
#elif NETSTANDARD2_1_OR_GREATER
return ++this.position < this.span.Length;
Expand All @@ -618,7 +618,7 @@ public readonly ref T Current
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
ref T r0 = ref this.reference;
#elif NETSTANDARD2_1_OR_GREATER
ref T r0 = ref this.span.DangerousGetReference();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public readonly Item Current
[EditorBrowsable(EditorBrowsableState.Never)]
public readonly ref struct Item
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
/// <summary>
/// The <typeparamref name="T"/> reference for the <see cref="Item"/> instance.
/// </summary>
Expand All @@ -112,7 +112,7 @@ public readonly ref struct Item
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Item(ref T value, int index)
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
this.reference = ref value;
this.index = index;
#else
Expand Down Expand Up @@ -146,7 +146,7 @@ public ref T Value
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return ref this.reference;
#elif NETSTANDARD2_1_OR_GREATER
return ref MemoryMarshal.GetReference(this.span);
Expand All @@ -167,7 +167,7 @@ public int Index
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
#if NET7_0_OR_GREATER
#if NET8_0_OR_GREATER
return this.index;
#elif NETSTANDARD2_1_OR_GREATER
return this.span.Length;
Expand Down
Loading