csharplang icon indicating copy to clipboard operation
csharplang copied to clipboard

[Proposal]: UTF-8 Literal Pattern Matching Support

Open 333fred opened this issue 3 years ago • 3 comments

UTF-8 Literal Pattern Matching Support

  • [x] Proposed
  • [ ] Prototype: Not Started
  • [ ] Implementation: Not Started
  • [ ] Specification: Not Started

The LDM looked at the concept and approved it in theory, but it needs an approved specification. This is in the Any Time milestone, so we'd accept a specification from a community member.

Original discussion: https://github.com/dotnet/csharplang/discussions/6036

Design Meetings

  • https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-05-11.md#pattern-matching-with-utf-8-string-literals

333fred avatar May 25 '22 00:05 333fred

@333fred I would like to try writing a specification for this proposal (will be able to start next week).

neon-sunset avatar Aug 02 '23 10:08 neon-sunset

Go for it, though I will be out until late August.

333fred avatar Aug 02 '23 15:08 333fred

It would be very useful if C# also provided the ability to specify a UTF-8 string (e.g., "MyUtf8String"u8) as a constant, which would then allow such constants to be used in the respective case statements of a switch statement. That would then have the potential to allow developers to more easily build much more efficient JsonConverter<T> implementations because at present, each JSON property is found/identified through a chain of if/else-if statements using Utf8JsonReader.ValueTextEquals calls.

If the switch statement performance improvements for switching string options implemented in .NET 8 were to be made available for UTF-8 strings and then employed in JsonConverter<T> implementations, we could see a significant performance boost in JSON deserialization.

bill-poole avatar Mar 16 '24 11:03 bill-poole