Skip to content

Commit f4faebe

Browse files
committed
Cache the PSCommand for the prompt
Since it doesn't change and we're always using it.
1 parent 9974c7d commit f4faebe

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/PowerShellEditorServices/Services/PowerShell/Host/PsesInternalHost.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ internal class PsesInternalHost : PSHost, IHostSupportsInteractiveSession, IRuns
3535
{
3636
internal const string DefaultPrompt = "> ";
3737

38+
private static readonly PSCommand s_promptCommand = new PSCommand().AddCommand("prompt");
39+
3840
private static readonly PropertyInfo s_scriptDebuggerTriggerObjectProperty;
3941

4042
private readonly ILoggerFactory _loggerFactory;
@@ -1026,10 +1028,8 @@ internal string GetPrompt(CancellationToken cancellationToken)
10261028
string prompt = DefaultPrompt;
10271029
try
10281030
{
1029-
// TODO: Should we cache PSCommands like this as static members?
1030-
PSCommand command = new PSCommand().AddCommand("prompt");
10311031
IReadOnlyList<string> results = InvokePSCommand<string>(
1032-
command,
1032+
s_promptCommand,
10331033
executionOptions: new PowerShellExecutionOptions { ThrowOnError = false },
10341034
cancellationToken);
10351035

0 commit comments

Comments
 (0)