Skip to content
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

Simple formatting cleanup over Uri #31874

Merged
merged 3 commits into from
Apr 29, 2020

Conversation

MihaZupan
Copy link
Member

@MihaZupan MihaZupan commented Feb 6, 2020

Usings, inline out params, indentation, discards etc (these aren't all such cases in Uri, I am just trying to split my changes into more reviewable chunks).

No behavioral changes.

@MihaZupan MihaZupan added this to the 5.0 milestone Feb 6, 2020
@MihaZupan MihaZupan requested review from stephentoub and a team February 6, 2020 17:42
@@ -49,7 +37,7 @@ internal static string ParseCanonicalName(string str, int start, int end, ref bo
//
// Assumption is the caller will check on the resulting name length
// Remarks: MUST NOT be used unless all input indexes are verified and trusted.
internal static unsafe bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile)
public static unsafe bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only one I'm not sure of; I've seen this inconsistency elsewhere and not sure if we have a recommendation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if we have a recommendation.

It might not be written down but the recommendation is to use 'internal' for classes that need to be used throughout the assembly (i.e. System.Private.Uri) but then use only 'public' or 'private' for methods, properties, etc.


Uri resultUri = new Uri(baseUri, testUri);

throwAway = resultUri.Port; // For Debugging.
_ = resultUri.Port; // For Debugging.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the // For Debugging comment mean? Is this functionally necessary? It sounds like it is for the port one above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code pattern above was probably used because there is a side-affect of doing a 'get' on the .Port property.

Will the behavior be the same if you use "_"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I am aware, the behavior is the same as assigning to a dummy local, but it makes it obvious which values aren't used and avoids analyzer warnings

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MihaZupan, I'm still not clear on what the "For Debugging" comment is referring to?

Copy link
Member Author

@MihaZupan MihaZupan Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it more, I think this is a possible reason why it was used:

Uri is currently parsed in 3 phases (lazy):

  1. In the ctor - identify the type of Uri, check the authority and other basic things to determine if the Uri is valid
  2. Determine offsets for UserInfo, Host, Path, parse the port value
  3. Determine the rest of offsets (Query, Fragment) and check if parts are in canonical form

This can make debugging harder. For example when debugging in Visual Studio, you must be careful to explicitly turn off the feature showing Locals - you can be stepping through the ctor and VS tries to evaluate properties like Query which trigger full parsing (before the initial ctor parsing even started), thus corrupting the Uri state under the debugger.
I've hit this when debugging Uri before and it took me a few hours to realize what was happening.

If the original author was debugging this code, they could have used code like

_ = uri.Port
Debugger.Launch();

to force more parsing before attaching the debugger, but forgot to remove it afterwards.

I've removed it.

@MihaZupan
Copy link
Member Author

Made a second pass over test files, please re-review

@davidsh
Copy link
Contributor

davidsh commented Feb 7, 2020

Made a second pass over test files, please re-review

I've noticed there are still comments on this PR that don't have answers from you. It would be helpful if you could review all of those, type in appropriate comments ("Fixed", "Not really a problem", etc.) and then click "Resolve" on the issue. That helps reviewers more quickly be able to re-review a PR. Thanks!

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my remaining comments, LGTM.

@MihaZupan MihaZupan reopened this Apr 28, 2020
@MihaZupan MihaZupan merged commit 00c99a7 into dotnet:master Apr 29, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants