-
Notifications
You must be signed in to change notification settings - Fork 348
Consider exposing Utf8Utility #2792
Comments
I believe you can call the public static bool TryCreateFrom(ReadOnlySpan<byte> buffer, [NotNullWhen(true)] out Utf8String? value) |
Thank you. You are right, I missed this api. It doesn't throw and works perfectly fine for my purpose. I'll close this issue unless there is anything else someone wants to start a discussion from. |
@Symbai If there's a particular API you'd like exposed (e.g., |
@GrabYourPitchforks I think my use case is too specific but as you're asking. Making On the other hand I could imagine this API may be useful for others as well to isolate the invalid sequence and deal with the them / the valid rest. Benchmark on my scenario with 1GB of memory chunk using Utf8String.TryCreate:
So thank all of you for adding Utf8String. I'm really excited for the release. |
I opened dotnet/runtime#502 to track your suggestion and added the appropriate labels so that it doesn't fall off the radar. Thanks for your feedback. :) |
I was trying out the Utf8String which has been added to 5.0 as it seems. Unfortunately creating an Utf8String from a byte array throws an ArgumentException if the byte array contains invalid utf8 code. While this makes sense in a way (in other ways not as Utf8Encoder.GetString does not throw) it sadly is a huge problem when performance matters.
The code reveals that there is a simple call to Utf8Utility.IsWellFormedUtf8 in the ctor and if it returns false it throws the exception. I would like to call this myself and skip Utf8String creation / exception. Unfortunately it is internal only.
https://github.com/dotnet/runtime/blob/4f9ae42d861fcb4be2fcd5d3d55d5f227d30e723/src/coreclr/src/System.Private.CoreLib/src/System/Utf8String.Construction.cs#L75-L80
Is there a chance to expose it or avoid exception thrown?
The text was updated successfully, but these errors were encountered: