-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
Splat.NLog - Reduce allocation when creating new NLogLogger #1258
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1258 +/- ##
==========================================
- Coverage 71.87% 71.71% -0.16%
==========================================
Files 96 96
Lines 4483 4430 -53
Branches 569 561 -8
==========================================
- Hits 3222 3177 -45
+ Misses 1074 1069 -5
+ Partials 187 184 -3 ☔ View full report in Codecov by Sentry. |
@@ -14,6 +14,7 @@ namespace Splat.NLog; | |||
[DebuggerDisplay("Name={_inner.Name} Level={Level}")] | |||
public sealed class NLogLogger : IFullLogger, IDisposable | |||
{ | |||
private static readonly LogLevel[] _allLogLevels = Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>().ToArray(); |
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.
Use the Enum.GetValues<T>
generic override, it's AOT compatible for future proofing.
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.
Enum.GetValues<T>
is only available for NET5 (and newer). But good point about AOT-support. Added new commit.
Also verified that Enum.GetValues<T>
allocates new array on every call, so caching still needed.
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.
Yeah caching is good. In AOT land they actually compile it to an array, but in non-AOT land its standard behavior.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
Enum.GetValues<T>
What might this PR break?
Please check if the PR fulfills these requirements
Other information: