Skip to content

Conversation

filzrev
Copy link
Contributor

@filzrev filzrev commented May 17, 2025

This PR fix build error when using .NET 10 preview4 (It's occurred only when using Visual Studio Preview)

It's caused because .NET 10 preview4 or later contains build-in InlineArray16<T> implementation.
So It need to exclude ZLinq's InlineArray16<T> implementation for .NET10 build.


Additionally .NET 10 preview 4 add following methods for FrozenCollection.

As far as I've confirmed.
These methods are simple wrapper and no performance benefits to use these methods.

Example Code

    public static FrozenSet<TSource> ToFrozenSet<TEnumerator, TSource>(this ValueEnumerable<TEnumerator, TSource> source, IEqualityComparer<TSource>? comparer = null)
       where TEnumerator : struct, IValueEnumerator<TSource>
#if NET9_0_OR_GREATER
        , allows ref struct
#endif
    {
#if NET10_0_OR_GREATER
        using var e = source.Enumerator;
        if (e.TryGetSpan(out var span))
            return FrozenSet.Create(comparer, span); // Almost same performance to `source.ToHashSet().ToFrozenSet()`

        // When using ToArrayPool. it run slower 10-20%
        using var pooledArray = source.ToArrayPool();
        span = pooledArray.Span;
        return FrozenSet.Create(comparer, span);
#else
        return source.ToHashSet(comparer).ToFrozenSet(comparer);
#endif
    }

@neuecc
Copy link
Member

neuecc commented May 18, 2025

Thank you!
I see, I completely forgot about the conflicts.
I understand about the Frozen***.Create too.
It seems fine to leave it as is for now, but I'll keep an eye on it.

@neuecc neuecc merged commit 04619ee into Cysharp:main May 18, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants