Open eiriktsarpalis opened 2 months ago
Tagging subscribers to this area: @dotnet/area-system-collections See info in area-owners.md if you want to be subscribed.
@eiriktsarpalis this is the first issue I come across that mentions this IAlternateEqualityComparer
. I searched for it and found nothing relevant. Would you mind linking to something that provides a bit more background on that interface and its use cases?
I think it has to be option 1 as it's not assumed byte arrays are utf8 anywhere else except in utf8 methods?
@bencyoung-Fignum I think so too, but I figured it would be worth mentioning that alternative given the dominance of UTF-8.
Motivation
This benchmark seems to suggest that building a string-based IAlternateEqualityComparer for
ReadOnlySpan<byte>
keys can have substantial performance and usability benefits over manually converting the key to an intermediateReadOnlySpan<char>
.We should enhance
StringComparer
with anIAlternateEqualityComparer<ReadOnlySpan<byte>, string>
implementation. I see a couple of potential approaches we could follow:Approach 1: Factory method in
System.Text.Encoding
orUTF8Encoding
Which can then be used as follows:
Approach 2: hardcoding UTF-8 equality comparison into
StringComparer
Title says it all, we could just make the assumption that UTF-8 is the encoding most people will end up using for
ROS<byte>
so we just bake it intoStringComparer
directly:cc @stephentoub @davidfowl