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

NLogMessageParameterList - Reduce code complexity for IsValidParameterList #333

Merged
merged 2 commits into from
Sep 16, 2019

Conversation

snakefoot
Copy link
Contributor

And micro-optimization for comparison against OriginalFormatPropertyName (skip null-check by using Equals for OriginalFormatPropertyName-object)

@codecov-io
Copy link

codecov-io commented Sep 15, 2019

Codecov Report

Merging #333 into master will increase coverage by 0.15%.
The diff coverage is 78.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #333      +/-   ##
==========================================
+ Coverage   81.82%   81.98%   +0.15%     
==========================================
  Files          12       12              
  Lines        1106     1110       +4     
  Branches      194      195       +1     
==========================================
+ Hits          905      910       +5     
+ Misses        138      136       -2     
- Partials       63       64       +1
Impacted Files Coverage Δ
src/NLog.Extensions.Logging/Logging/NLogLogger.cs 80.29% <100%> (-0.37%) ⬇️
...Extensions.Logging/Logging/NLogBeginScopeParser.cs 66.43% <50%> (ø) ⬆️
...nsions.Logging/Logging/NLogMessageParameterList.cs 91.72% <80%> (+1.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93b54d3...311f149. Read the comment docs.

originalMessageIndex = null;
bool? firstParameterIsPositional = null;
isPositional = false;
string parameterName;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this one moved to the outer scope?

Copy link
Contributor Author

@snakefoot snakefoot Sep 15, 2019

Choose a reason for hiding this comment

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

Old c++ habbit. No need to push the same parameter on the stack for every loop-iteration

Copy link
Member

Choose a reason for hiding this comment

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

In my experience is could cause memory leaks.

Copy link
Member

Choose a reason for hiding this comment

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

And I think it's a code smell in Sonar, not sure

Copy link
Contributor Author

@snakefoot snakefoot Sep 15, 2019

Choose a reason for hiding this comment

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

Only tried memory leaks in C# with dangling event-handlers or dispose-handles (keeps things alive after lifetime) or dynamic-compiled-code (can never be freed).

char firstChar = parameterKey[0];
if (GetCaptureType(firstChar) != CaptureType.Normal)
char firstChar = parameterName[0];
if (firstChar >= '0' && firstChar <= '9')
Copy link
Member

Choose a reason for hiding this comment

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

I think this check is more expensive than before. but maybe not really significant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most users will always use CaptureType.Normal. Doing the isPositional-check first makes the code simpler. It will only change performance for those who always use @ in the parameter-tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal of this PR is to reduce the complexity of IsValidParameterList with minimal impact.

@304NotModified
Copy link
Member

Any idea if the coverage is really reduced? Or is it a flaky coverage test?

@304NotModified 304NotModified added this to the 1.5.5 milestone Sep 16, 2019
@snakefoot
Copy link
Contributor Author

Any idea if the coverage is really reduced? Or is it a flaky coverage test?

Have now increased the code-coverage.

@304NotModified 304NotModified merged commit c6579b5 into NLog:master Sep 16, 2019
@304NotModified
Copy link
Member

Merged! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants