Skip to content

Address PR feedback from #2579 #2611

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

Merged
merged 1 commit into from
Feb 20, 2019
Merged

Conversation

eerhardt
Copy link
Member

We don't need a TryConvert method, we already have a TryParse, which can be used instead.

We don't need a TryConvert method, we already have a TryParse, which can be used instead.
int csrc = 0;
if (!Conversions.Instance.TryConvert(in spanT, ref csrc) || csrc <= 0)
int csrc;
if (!Conversions.Instance.TryParse(in spanT, out csrc) || csrc <= 0)
Copy link
Member

@stephentoub stephentoub Feb 19, 2019

Choose a reason for hiding this comment

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

Note that TryParse is going to be slightly more expensive, but it's unlikely to be measurable, especially given everything else going on here.

Copy link
Member Author

Choose a reason for hiding this comment

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

slightly more expensive

Because of the extra write to the out parameter? Or because of the under/overflow check? Or something else?

Copy link
Member

@stephentoub stephentoub Feb 19, 2019

Choose a reason for hiding this comment

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

The extra indirect write in the case of success, two extra indirect writes in the case of failure, the overflow check, the cast from the nullable rather than GetValueOrDefault, larger code that's even less likely to be inlined (though it's probably already not getting inlined). In general this code is not particularly clean.

@stephentoub
Copy link
Member

This begs the question why the methods are named Convert and TryParse, rather than Convert and TryConvert, or Parse and TryParse. As long as you're cleaning things up, seems it should be consistent.

@codecov
Copy link

codecov bot commented Feb 19, 2019

Codecov Report

Merging #2611 into master will increase coverage by <.01%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master    #2611      +/-   ##
==========================================
+ Coverage   71.53%   71.53%   +<.01%     
==========================================
  Files         800      800              
  Lines      141866   141857       -9     
  Branches    16122    16121       -1     
==========================================
- Hits       101478   101475       -3     
+ Misses      35937    35931       -6     
  Partials     4451     4451
Flag Coverage Δ
#Debug 71.53% <0%> (ø) ⬆️
#production 67.81% <0%> (ø) ⬆️
#test 85.78% <ø> (+0.01%) ⬆️

Copy link
Contributor

@TomFinley TomFinley left a comment

Choose a reason for hiding this comment

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

Looks good thank you @eerhardt

@eerhardt eerhardt merged commit eb7c121 into dotnet:master Feb 20, 2019
@eerhardt eerhardt deleted the FollowUp2579 branch February 20, 2019 20:28
@eerhardt
Copy link
Member Author

@stephentoub - I've logged #2669 for your concerns on the existing TryParse code.

@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants