Skip to content

Conversation

@AlexRadch
Copy link
Contributor

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.

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.
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 13, 2025
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)]);
Copy link
Contributor

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?

Copy link
Contributor Author

@AlexRadch AlexRadch Jan 13, 2025

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?

Copy link
Contributor Author

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.
@ericstj
Copy link
Member

ericstj commented Jan 28, 2025

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ericstj ericstj assigned ericstj and unassigned JeremyKuhne Mar 10, 2025
Copy link
Member

@ericstj ericstj left a 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

@ericstj
Copy link
Member

ericstj commented Mar 18, 2025

/ba-g failures are networking test flakiness

@ericstj ericstj merged commit 350b9cb into dotnet:main Mar 18, 2025
79 of 82 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.ComponentModel community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SizeConverter is trying to convert even before verifying the value could be converted

5 participants