-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Use uint.TryFormat to fix TODO in IPAddressParser #117300
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
base: main
Are you sure you want to change the base?
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 replaces the manual digit-by-digit formatting of the IPv6 scope ID with a call to uint.TryFormat
, removing the TODO and reducing code complexity.
- Added a
Debug.Assert
to ensureTChar
is eitherbyte
orchar
. - Replaced manual
stackalloc
formatting with a singleTryFormat
call for bothbyte
andchar
. - Removed the old loop-based formatting and related TODO comment.
Comments suppressed due to low confidence (1)
src/libraries/System.Net.Primitives/src/System/Net/IPAddressParser.cs:225
- Add unit tests covering the new
TryFormat
logic for bothTChar = char
andTChar = byte
to ensure the IPv6 scope ID formatting is exercised in all scenarios.
bool formatted = typeof(TChar) == typeof(byte) ?
Tagging subscribers to this area: @dotnet/ncl |
used.CopyTo(destination.Slice(pos)); | ||
pos += used.Length; | ||
int bytesWritten; | ||
bool formatted = typeof(TChar) == typeof(byte) ? |
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.
Do we want to switch to TryFormat
in the local functions FormatByte
and AppendHex
in this file too?
No description provided.