mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Minor perf tweaks (#5289)
* Avoid creating scriptblocks unnecessarily in PSScriptProperty * Use string.IsNullOrWhiteSpace instead of Trim().Length
This commit is contained in:
@@ -150,7 +150,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
@@ -2434,7 +2434,7 @@ namespace Microsoft.PowerShell
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.Trim().Length == 0)
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
if (inBlockMode)
|
||||
{
|
||||
|
||||
@@ -901,7 +901,7 @@ namespace System.Management.Automation
|
||||
string resourceId,
|
||||
params object[] args)
|
||||
{
|
||||
if (String.IsNullOrEmpty(template) || 1 >= template.Trim().Length)
|
||||
if (string.IsNullOrWhiteSpace(template))
|
||||
{
|
||||
_textLookupError = PSTraceSource.NewInvalidOperationException(
|
||||
ErrorPackage.ErrorDetailsEmptyTemplate,
|
||||
|
||||
@@ -195,7 +195,7 @@ namespace System.Management.Automation.Runspaces
|
||||
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 @@ namespace System.Management.Automation.Runspaces
|
||||
public SessionStateFormatEntry(string fileName)
|
||||
: base("*")
|
||||
{
|
||||
if (String.IsNullOrEmpty(fileName) || fileName.Trim().Length == 0)
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
throw PSTraceSource.NewArgumentException("fileName");
|
||||
}
|
||||
|
||||
@@ -1782,7 +1782,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.SetterScript != null;
|
||||
return this._setterScript != null || this._setterScriptText != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1793,7 +1793,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetterScript != null;
|
||||
return this._getterScript != null || this._getterScriptText != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace System.Management.Automation.Runspaces
|
||||
{
|
||||
if (name != null)
|
||||
{
|
||||
if (name.Trim().Length == 0)
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
throw PSTraceSource.NewArgumentException("name");
|
||||
}
|
||||
@@ -105,7 +105,7 @@ namespace System.Management.Automation.Runspaces
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user