mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Refactor multiply operation for better performance in 2 Commands.Utility functions (#14148)
This commit is contained in:
@@ -623,7 +623,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
object currentValue = objValue;
|
||||
object statValue = statMinOrMaxValue;
|
||||
int factor = isMin ? 1 : -1;
|
||||
|
||||
double temp;
|
||||
currentValue = ((objValue != null) && LanguagePrimitives.TryConvertTo<double>(objValue, out temp)) ? temp : currentValue;
|
||||
@@ -635,13 +634,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
statValue = PSObject.AsPSObject(statValue).ToString();
|
||||
}
|
||||
|
||||
if ((statValue == null) ||
|
||||
((LanguagePrimitives.Compare(statValue, currentValue, false, CultureInfo.CurrentCulture) * factor) > 0))
|
||||
if (statValue == null)
|
||||
{
|
||||
return objValue;
|
||||
}
|
||||
|
||||
return statMinOrMaxValue;
|
||||
int comparisonResult = LanguagePrimitives.Compare(statValue, currentValue, ignoreCase: false, CultureInfo.CurrentCulture);
|
||||
return (isMin ? comparisonResult : -comparisonResult) > 0
|
||||
? objValue
|
||||
: statMinOrMaxValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+10
-10
@@ -210,19 +210,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
second = secondMsh.BaseObject;
|
||||
}
|
||||
|
||||
if (LanguagePrimitives.TryCompare(first, second, !_caseSensitive, _cultureInfo, out int result))
|
||||
if (!LanguagePrimitives.TryCompare(first, second, !_caseSensitive, _cultureInfo, out int result))
|
||||
{
|
||||
return result * (_ascendingOrder ? 1 : -1);
|
||||
// Note that this will occur if the objects do not support
|
||||
// IComparable. We fall back to comparing as strings.
|
||||
|
||||
// being here means the first object doesn't support ICompare
|
||||
string firstString = PSObject.AsPSObject(first).ToString();
|
||||
string secondString = PSObject.AsPSObject(second).ToString();
|
||||
|
||||
result = _cultureInfo.CompareInfo.Compare(firstString, secondString, _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase);
|
||||
}
|
||||
|
||||
// Note that this will occur if the objects do not support
|
||||
// IComparable. We fall back to comparing as strings.
|
||||
|
||||
// being here means the first object doesn't support ICompare
|
||||
string firstString = PSObject.AsPSObject(first).ToString();
|
||||
string secondString = PSObject.AsPSObject(second).ToString();
|
||||
|
||||
return _cultureInfo.CompareInfo.Compare(firstString, secondString, _caseSensitive ? CompareOptions.None : CompareOptions.IgnoreCase) * (_ascendingOrder ? 1 : -1);
|
||||
return _ascendingOrder ? result : -result;
|
||||
}
|
||||
|
||||
private readonly CultureInfo _cultureInfo = null;
|
||||
|
||||
Reference in New Issue
Block a user