-
Notifications
You must be signed in to change notification settings - Fork 5k
Remove unsafe code from Http KnownHeaders #114757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes unsafe code from the KnownHeaders implementation and simplifies header candidate lookup by eliminating the redundant IHeaderNameAccessor interface and related types. The key changes are:
- Removal of the unsafe IHeaderNameAccessor interface and its implementations.
- Refactoring of GetCandidate to work with ReadOnlySpan and a new generic constraint.
- Exposure of TryGetKnownHeader methods as public.
Comments suppressed due to low confidence (2)
src/libraries/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs:125
- Ensure that both 'char' and 'byte' types implement INumberBase so the new generic constraint works as expected when using GetCandidate.
private static KnownHeader? GetCandidate<T>(ReadOnlySpan<T> key)
src/libraries/System.Net.Http/src/System/Net/Http/Headers/KnownHeaders.cs:395
- Verify that removing the fixed block for the ReadOnlySpan overload does not introduce any unintended performance regressions or memory safety issues.
KnownHeader? candidate = GetCandidate(name);
Tagging subscribers to this area: @dotnet/ncl |
This also gets rid of the redundant bounds checks for the
char
variant.For
byte
the codegen is the same.