-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add cache for GetApplicationBase #3969
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
Add cache for GetApplicationBase #3969
Conversation
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.
How about having an internal static property named DefaultPowerShellAppBase like this:
internal static string DefaultPowerShellAppBase { get; } = GetApplicationBase(DefaultPowerShellShellID);And then use this get-only property in places where GetApplicationBase(DefaultPowerShellShellID) is used.
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.
Good catch!
Done.
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.
With that getter-only property, you won't need this method.
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.
Fixed.
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.
With that getter-only property, you won't need to add this.
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.
Fixed.
|
@iSazonov Sorry about the late review 😦 |
Clean up code to use cached value s_GetApplicationBaseDefaultPowerShell
debbae4 to
b06e43a
Compare
| if (DefaultPowerShellAppBase != null) | ||
| { | ||
| return DefaultPowerShellAppBase; | ||
| } |
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.
This is a bit confusing -- looks like a recursion would happen even though it's not. I suggest removing this if block.
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.
Fixed.
|
@daxian-dbw Thanks for the code review! |
Motivation
We call Utils.GetApplicationBase() multiple times at startup and later so we need cache the one to exclude a reflection.
Fix
DefaultPowerShellAppBaseinUtils.cs.Additional considerations
Code that uses a ShellId from Context has not been changed, although it is only associated with the Windows PowerShell (FullCLR).