Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add cache for GetApplicationBase#3969

Merged
daxian-dbw merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:cache-for-getapplicationbaseiSazonov/PowerShell:cache-for-getapplicationbaseCopy head branch name to clipboard
Jun 20, 2017
Merged

Add cache for GetApplicationBase#3969
daxian-dbw merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:cache-for-getapplicationbaseiSazonov/PowerShell:cache-for-getapplicationbaseCopy head branch name to clipboard

Conversation

@iSazonov

@iSazonov iSazonov commented Jun 8, 2017

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.