-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Refactor geometric type converters for improved parsing #111349
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
This commit refactors the parsing logic for string representations of geometric types (Point, Rectangle, Size, SizeF) by using `Span<Range>` to enhance performance and reduce memory allocations. Exception handling has been improved with more specific error messages for parsing failures. Additionally, tests have been updated to reflect changes in expected values and formats, covering a wider range of cases, including edge cases and whitespace handling. The syntax for array initialization has been modernized to use collection initializers for better readability. Overall, these changes enhance the robustness, readability, and performance of the type conversion code.
src/libraries/System.ComponentModel.TypeConverter/src/System/Drawing/SizeConverter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.ComponentModel.TypeConverter/src/System/Drawing/SizeFConverter.cs
Outdated
Show resolved
Hide resolved
This commit refactors the `CanConvertTo` method in the `PointConverter`, `RectangleConverter`, `SizeConverter`, and `SizeFConverter` classes. The changes enhance readability and maintainability by replacing the use of an array to hold converted values with direct string interpolation for constructing the return value. This results in clearer and more concise code.
| ConstructorInfo? ctor = typeof(Rectangle).GetConstructor(new Type[] { | ||
| typeof(int), typeof(int), typeof(int), typeof(int)}); | ||
| ConstructorInfo? ctor = typeof(Rectangle).GetConstructor( | ||
| [typeof(int), typeof(int), typeof(int), typeof(int)]); |
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.
Can these param lists be static readonly arrays?
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.
Can I once ask for ConstructorInfo and remember it or should I not do that?
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.
I thought that creating the InstanceDescriptor class is a rare operation and we shouldn't consume memory to speed it up.
Refactor the `ConvertFrom` method in `PointConverter`, `RectangleConverter`, `SizeConverter`, and `SizeFConverter` to use `AsSpan().Trim()` for improved performance by reducing string allocations.
|
/azp run runtime |
|
Azure Pipelines successfully started running 1 pipeline(s). |
ericstj
left a comment
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.
Changes LGTM, thank you for the improvement
|
/ba-g failures are networking test flakiness |
Close #92424
This commit refactors the parsing logic for string representations of geometric types (Point, Rectangle, Size, SizeF) by using
Span<Range>to enhance performance and reduce memory allocations.Exception handling has been improved with more specific error messages for parsing failures.
Additionally, tests have been updated to reflect changes in expected values and formats, covering a wider range of cases, including edge cases and whitespace handling.
The syntax for array initialization has been modernized to use collection initializers for better readability.
Overall, these changes enhance the robustness, readability, and performance of the type conversion code.