Skip to content

Commit

Permalink
Switch solution to C# 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Nov 22, 2023
1 parent 9b5972c commit cc6c38e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

Expand Down
18 changes: 5 additions & 13 deletions src/PolySharp.SourceGenerators/Helpers/EquatableArray{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,14 @@ public static EquatableArray<T> AsEquatableArray<T>(this ImmutableArray<T> array
/// An imutable, equatable array. This is equivalent to <see cref="ImmutableArray{T}"/> but with value equality support.
/// </summary>
/// <typeparam name="T">The type of values in the array.</typeparam>
internal readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>, IEnumerable<T>
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
internal readonly struct EquatableArray<T>(ImmutableArray<T> array) : IEquatable<EquatableArray<T>>, IEnumerable<T>
where T : IEquatable<T>
{
/// <summary>
/// The underlying <typeparamref name="T"/> array.
/// </summary>
private readonly T[]? array;

/// <summary>
/// Creates a new <see cref="EquatableArray{T}"/> instance.
/// </summary>
/// <param name="array">The input <see cref="ImmutableArray{T}"/> to wrap.</param>
public EquatableArray(ImmutableArray<T> array)
{
this.array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);
}
private readonly T[]? array = Unsafe.As<ImmutableArray<T>, T[]?>(ref array);

/// <summary>
/// Gets a reference to an item at a specified position within the array.
Expand Down Expand Up @@ -144,7 +136,7 @@ public static EquatableArray<T> FromImmutableArray(ImmutableArray<T> array)
/// <returns>A <see cref="ReadOnlySpan{T}"/> wrapping the current items.</returns>
public ReadOnlySpan<T> AsSpan()
{
return AsImmutableArray().AsSpan();
return new(this.array);
}

/// <summary>
Expand All @@ -153,7 +145,7 @@ public ReadOnlySpan<T> AsSpan()
/// <returns>The newly instantiated array.</returns>
public T[] ToArray()
{
return AsImmutableArray().ToArray();
return [.. AsSpan()];
}

/// <summary>
Expand Down

0 comments on commit cc6c38e

Please sign in to comment.