From c75357b192c5eb8e06abcda6db594de33b2ad6ea Mon Sep 17 00:00:00 2001 From: Jason Shirk Date: Wed, 1 Nov 2017 13:32:43 -0700 Subject: [PATCH] Minor perf tweaks (#5289) * Avoid creating scriptblocks unnecessarily in PSScriptProperty * Use string.IsNullOrWhiteSpace instead of Trim().Length --- .../commands/management/WebServiceProxy.cs | 2 +- src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs | 2 +- src/System.Management.Automation/engine/ErrorPackage.cs | 2 +- .../engine/InitialSessionState.cs | 4 ++-- src/System.Management.Automation/engine/MshMemberInfo.cs | 4 ++-- .../engine/hostifaces/Parameter.cs | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs index e1ee08b2fbb..7ddb52ec825 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/WebServiceProxy.cs @@ -150,7 +150,7 @@ public SwitchParameter UseDefaultCredential /// protected override void BeginProcessing() { - if (_uri.ToString().Trim().Length == 0) + if (string.IsNullOrWhiteSpace(_uri.ToString())) { Exception ex = new ArgumentException(WebServiceResources.InvalidUri); ErrorRecord er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.InvalidOperation, null); diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 5a4c3768b29..ae01316a89b 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -2434,7 +2434,7 @@ internal void Run(bool inputLoopIsNested) continue; } - if (line.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(line)) { if (inBlockMode) { diff --git a/src/System.Management.Automation/engine/ErrorPackage.cs b/src/System.Management.Automation/engine/ErrorPackage.cs index 1086e842668..44c275e6886 100644 --- a/src/System.Management.Automation/engine/ErrorPackage.cs +++ b/src/System.Management.Automation/engine/ErrorPackage.cs @@ -901,7 +901,7 @@ private string BuildMessage( string resourceId, params object[] args) { - if (String.IsNullOrEmpty(template) || 1 >= template.Trim().Length) + if (string.IsNullOrWhiteSpace(template)) { _textLookupError = PSTraceSource.NewInvalidOperationException( ErrorPackage.ErrorDetailsEmptyTemplate, diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 6b57a8318de..e1743936035 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -195,7 +195,7 @@ public sealed class SessionStateTypeEntry : InitialSessionStateEntry public SessionStateTypeEntry(string fileName) : base(fileName) { - if (String.IsNullOrEmpty(fileName) || fileName.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(fileName)) { throw PSTraceSource.NewArgumentException("fileName"); } @@ -300,7 +300,7 @@ public sealed class SessionStateFormatEntry : InitialSessionStateEntry public SessionStateFormatEntry(string fileName) : base("*") { - if (String.IsNullOrEmpty(fileName) || fileName.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(fileName)) { throw PSTraceSource.NewArgumentException("fileName"); } diff --git a/src/System.Management.Automation/engine/MshMemberInfo.cs b/src/System.Management.Automation/engine/MshMemberInfo.cs index eb32b76fbe5..aeee875090e 100644 --- a/src/System.Management.Automation/engine/MshMemberInfo.cs +++ b/src/System.Management.Automation/engine/MshMemberInfo.cs @@ -1782,7 +1782,7 @@ public override bool IsSettable { get { - return this.SetterScript != null; + return this._setterScript != null || this._setterScriptText != null; } } @@ -1793,7 +1793,7 @@ public override bool IsGettable { get { - return this.GetterScript != null; + return this._getterScript != null || this._getterScriptText != null; } } diff --git a/src/System.Management.Automation/engine/hostifaces/Parameter.cs b/src/System.Management.Automation/engine/hostifaces/Parameter.cs index 9818cb5ac19..b87e14f8bc3 100644 --- a/src/System.Management.Automation/engine/hostifaces/Parameter.cs +++ b/src/System.Management.Automation/engine/hostifaces/Parameter.cs @@ -49,7 +49,7 @@ public CommandParameter(string name, object value) { if (name != null) { - if (name.Trim().Length == 0) + if (string.IsNullOrWhiteSpace(name)) { throw PSTraceSource.NewArgumentException("name"); } @@ -105,7 +105,7 @@ internal static CommandParameter FromCommandParameterInternal(CommandParameterIn Diagnostics.Assert(name != null, "'name' variable should be initialized at this point"); Diagnostics.Assert(name[0].IsDash(), "first character in parameter name must be a dash"); - Diagnostics.Assert(name.Trim().Length != 0, "Parameter name has to have some non-whitespace characters in it"); + Diagnostics.Assert(name.Trim().Length != 1, "Parameter name has to have some non-whitespace characters in it"); } if (internalParameter.ParameterAndArgumentSpecified)