Skip to content

Commit

Permalink
Minor perf tweaks (PowerShell#5289)
Browse files Browse the repository at this point in the history
* Avoid creating scriptblocks unnecessarily in PSScriptProperty
* Use string.IsNullOrWhiteSpace instead of Trim().Length
  • Loading branch information
lzybkr committed Nov 1, 2017
1 parent d43b2cf commit c75357b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public SwitchParameter UseDefaultCredential
/// </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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@ internal void Run(bool inputLoopIsNested)
continue;
}

if (line.Trim().Length == 0)
if (string.IsNullOrWhiteSpace(line))
{
if (inBlockMode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/ErrorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/MshMemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1782,7 +1782,7 @@ public override bool IsSettable
{
get
{
return this.SetterScript != null;
return this._setterScript != null || this._setterScriptText != null;
}
}

Expand All @@ -1793,7 +1793,7 @@ public override bool IsGettable
{
get
{
return this.GetterScript != null;
return this._getterScript != null || this._getterScriptText != null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c75357b

Please sign in to comment.