Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Jun 8, 2017

Motivation

We call Utils.GetApplicationBase() multiple times at startup and later so we need cache the one to exclude a reflection.

Fix

  1. Add a static getter-only property named DefaultPowerShellAppBase in Utils.cs.
  2. Refactor code to directly use cached value.

Additional considerations

Code that uses a ShellId from Context has not been changed, although it is only associated with the Windows PowerShell (FullCLR).

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!

Done.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@daxian-dbw
Copy link
Member

@iSazonov Sorry about the late review 😦

iSazonov added 2 commits June 20, 2017 09:32
Clean up code to use cached value s_GetApplicationBaseDefaultPowerShell
@iSazonov iSazonov force-pushed the cache-for-getapplicationbase branch from debbae4 to b06e43a Compare June 20, 2017 06:34
if (DefaultPowerShellAppBase != null)
{
return DefaultPowerShellAppBase;
}
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@daxian-dbw daxian-dbw merged commit 598cebf into PowerShell:master Jun 20, 2017
@iSazonov iSazonov deleted the cache-for-getapplicationbase branch June 21, 2017 05:34
@iSazonov
Copy link
Collaborator Author

@daxian-dbw Thanks for the code review!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants