Summary
Methods in StringUtilities.cs could have implementation without 'unsafe' keyword. It would allow HttpUtilities.GetHeaderName to also become safe as .NET 9 supports passing Span<T> (to generic type parameters).
Motivation and goals
Code becomes somewhat safer, no pointer arithmetic required, no 'pinning' by fixed would be required.
In scope
TryGetAsciiString could use Span<T> instead of char* and byte*, and methods using this could also become safe.
Risks / unknowns
It would still require a fair amount of Unsafe.As<> and Vector256.LoadUnsafe, MemoryMarshal.Cast etc.
The code is perf sensitive, but I believe the safe code would be still on-par with perf.
Other consideration
Could also consider adding Vector512 support on the way.
Summary
Methods in StringUtilities.cs could have implementation without 'unsafe' keyword. It would allow
HttpUtilities.GetHeaderNameto also become safe as .NET 9 supports passingSpan<T>(to generic type parameters).Motivation and goals
Code becomes somewhat safer, no pointer arithmetic required, no 'pinning' by
fixedwould be required.In scope
TryGetAsciiStringcould useSpan<T>instead ofchar*andbyte*, and methods using this could also become safe.Risks / unknowns
It would still require a fair amount of
Unsafe.As<>andVector256.LoadUnsafe,MemoryMarshal.Castetc.The code is perf sensitive, but I believe the safe code would be still on-par with perf.
Other consideration
Could also consider adding
Vector512support on the way.