Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ internal static string GetRandomPassword(int passwordLength)

for (int i = 0; i < passwordLength; i++)
{
chars[i] = (char)(randomBytes[i] % allowedCharsCount + charMin);
chars[i] = (char)((randomBytes[i] % allowedCharsCount) + charMin);
}

return new string(chars);
Expand Down Expand Up @@ -2013,8 +2013,8 @@ internal static bool IsComputerNameValid(string computerName)

foreach (char t in computerName)
{
if (t >= 'A' && t <= 'Z' ||
t >= 'a' && t <= 'z')
if ((t >= 'A' && t <= 'Z') ||
(t >= 'a' && t <= 'z'))
{
allDigits = false;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,13 +1159,13 @@ internal static DateTime UnixSecondsToDateTime(long seconds)
return DateTimeOffset.FromUnixTimeSeconds(seconds).DateTime;
#else
const int DaysPerYear = 365;
const int DaysPer4Years = DaysPerYear * 4 + 1;
const int DaysPer100Years = DaysPer4Years * 25 - 1;
const int DaysPer400Years = DaysPer100Years * 4 + 1;
const int DaysTo1970 = DaysPer400Years * 4 + DaysPer100Years * 3 + DaysPer4Years * 17 + DaysPerYear;
const int DaysPer4Years = (DaysPerYear * 4) + 1;
const int DaysPer100Years = (DaysPer4Years * 25) - 1;
const int DaysPer400Years = (DaysPer100Years * 4) + 1;
const int DaysTo1970 = (DaysPer400Years * 4) + (DaysPer100Years * 3) + (DaysPer4Years * 17) + DaysPerYear;
Comment on lines 1162 to 1165
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most people it is obvious that multiplication has a higher precedence than addition, so the parenthesis are probably not necessary. However while readability might not be any better, it is not really any worse.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

const long UnixEpochTicks = TimeSpan.TicksPerDay * DaysTo1970;

long ticks = seconds * TimeSpan.TicksPerSecond + UnixEpochTicks;
long ticks = (seconds * TimeSpan.TicksPerSecond) + UnixEpochTicks;

return new DateTimeOffset(ticks, TimeSpan.Zero).DateTime;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ private byte[] GetSendBuffer(int bufferSize)

for (int i = 0; i < bufferSize; i++)
{
sendBuffer[i] = (byte)((int)'a' + i % 23);
sendBuffer[i] = (byte)((int)'a' + (i % 23));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

}

if (bufferSize == DefaultSendBufferSize && s_DefaultSendBuffer == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ private string BuildErrorMessage(Diagnostic diagnisticRecord)
var errorLineString = textLines[errorLineNumber].ToString();
var errorPosition = lineSpan.StartLinePosition.Character;

StringBuilder sb = new StringBuilder(diagnisticMessage.Length + errorLineString.Length * 2 + 4);
StringBuilder sb = new StringBuilder(diagnisticMessage.Length + (errorLineString.Length * 2) + 4);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive


sb.AppendLine(diagnisticMessage);
sb.AppendLine(errorLineString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private double GetRandomDouble(double minValue, double maxValue)
do
{
double r = Generator.NextDouble();
randomNumber = minValue + r * maxValue - r * minValue;
randomNumber = minValue + (r * maxValue) - (r * minValue);
}
while (randomNumber >= maxValue);
}
Expand All @@ -333,7 +333,7 @@ private double GetRandomDouble(double minValue, double maxValue)
do
{
double r = Generator.NextDouble();
randomNumber = minValue + r * diff;
randomNumber = minValue + (r * diff);
diff = diff * r;
}
while (randomNumber >= maxValue);
Expand Down Expand Up @@ -385,7 +385,7 @@ private Int64 GetRandomInt64(Int64 minValue, Int64 maxValue)
randomUint64 &= mask;
} while (uint64Diff <= randomUint64);

double randomNumber = minValue * 1.0 + randomUint64 * 1.0;
double randomNumber = (minValue * 1.0) + (randomUint64 * 1.0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

return (Int64)randomNumber;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ protected override void BeginProcessing()
// whether the RemoteScript debug option is selected.
if (this.Context.InternalHost.ExternalHost is System.Management.Automation.Remoting.ServerRemoteHost &&
((this.Context.CurrentRunspace == null) || (this.Context.CurrentRunspace.Debugger == null) ||
((this.Context.CurrentRunspace.Debugger.DebugMode & DebugModes.RemoteScript) != DebugModes.RemoteScript) &&
(this.Context.CurrentRunspace.Debugger.DebugMode != DebugModes.None)))
(((this.Context.CurrentRunspace.Debugger.DebugMode & DebugModes.RemoteScript) != DebugModes.RemoteScript) &&
(this.Context.CurrentRunspace.Debugger.DebugMode != DebugModes.None))))
Comment thread
xtqqczze marked this conversation as resolved.
Outdated
{
ThrowTerminatingError(
new ErrorRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2006,8 +2006,8 @@ internal string ReadLineWithTabCompletion(Executor exec)
// the user hit tab up to the current cursor position after writing the completed text.

int deltaInput =
(endOfInputCursorPos.Y * screenBufferSize.Width + endOfInputCursorPos.X)
- (endOfCompletionCursorPos.Y * screenBufferSize.Width + endOfCompletionCursorPos.X);
((endOfInputCursorPos.Y * screenBufferSize.Width) + endOfInputCursorPos.X)
- ((endOfCompletionCursorPos.Y * screenBufferSize.Width) + endOfCompletionCursorPos.X);
Comment on lines 2009 to 2010
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less readability.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive


if (deltaInput > 0)
{
Expand Down Expand Up @@ -2066,7 +2066,7 @@ private void SendLeftArrows(int length)
up.Data.Keyboard.ExtraInfo = IntPtr.Zero;

inputs[2 * i] = down;
inputs[2 * i + 1] = up;
inputs[(2 * i) + 1] = up;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wonder if anybody wanted parentheses in such expressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiplicative > Additive

}

ConsoleControl.MimicKeyPress(inputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ public static Array ConvertToFileTimeArray(UnsafeNativeMethods.EvtVariant val)
for (int i = 0; i < val.Count; i++)
{
array[i] = DateTime.FromFileTime(Marshal.ReadInt64(ptr));
ptr = new IntPtr((Int64)ptr + 8 * sizeof(byte)); // FILETIME values are 8 bytes
ptr = new IntPtr((Int64)ptr + (8 * sizeof(byte))); // FILETIME values are 8 bytes
}

return array;
Expand All @@ -1441,7 +1441,7 @@ public static Array ConvertToSysTimeArray(UnsafeNativeMethods.EvtVariant val)
{
UnsafeNativeMethods.SystemTime sysTime = Marshal.PtrToStructure<UnsafeNativeMethods.SystemTime>(ptr);
array[i] = new DateTime(sysTime.Year, sysTime.Month, sysTime.Day, sysTime.Hour, sysTime.Minute, sysTime.Second, sysTime.Milliseconds);
ptr = new IntPtr((Int64)ptr + 16 * sizeof(byte)); // SystemTime values are 16 bytes
ptr = new IntPtr((Int64)ptr + (16 * sizeof(byte))); // SystemTime values are 16 bytes
}

return array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3626,7 +3626,7 @@ public static string GetDSCResourceUsageString(DynamicKeyword keyword)
}

var propVal = prop.Value;
if (listKeyProperties && propVal.IsKey || !listKeyProperties && !propVal.IsKey)
if ((listKeyProperties && propVal.IsKey) || (!listKeyProperties && !propVal.IsKey))
{
usageString.Append(propVal.Mandatory ? " " : " [ ");
usageString.Append(prop.Key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private int CurrentTableWidth(Span<int> columnWidths)
}
}

return sum + _separatorWidth * (visibleColumns - 1);
return sum + (_separatorWidth * (visibleColumns - 1));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ internal List<PacketInfoData> Add(PacketInfoData o)
}

// STATE TRANSITION: we are processing and we stop
if (_processingGroup &&
if ((_processingGroup &&
((o is GroupEndData) ||
(_objectCount > 0) && (_currentObjectCount >= _objectCount)) ||
((_objectCount > 0) && (_currentObjectCount >= _objectCount)))) ||
((_groupingTimer != null) && (_groupingTimer.Elapsed > _groupingDuration))
Comment thread
xtqqczze marked this conversation as resolved.
Outdated
)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal static int ComputeWideViewBestItemsPerRowFit(int stringLen, int screenC
// would we fit with one more column?
int nextValue = columnNumber + 1;
// compute the width if we added the extra column
int width = stringLen * nextValue + (nextValue - 1) * ScreenInfo.separatorCharacterCount;
int width = (stringLen * nextValue) + ((nextValue - 1) * ScreenInfo.separatorCharacterCount);

if (width >= screenColumns)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ private static void EnsureOrderOfPositionalParameters(

if ((maxBeforePosition >= 0) && (minAfterPosition <= maxBeforePosition))
{
int delta = (1001 - minAfterPosition % 1000);
int delta = (1001 - (minAfterPosition % 1000));
foreach (ParameterMetadata afterParameter in afterParameters.Values)
{
foreach (ParameterSetMetadata afterParameterSet in afterParameter.ParameterSets.Values)
Expand Down
12 changes: 6 additions & 6 deletions src/System.Management.Automation/engine/COM/ComInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static unsafe IntPtr NewVariantArray(int length)

for (int i = 0; i < length; i++)
{
IntPtr currentVarPtr = variantArray + s_variantSize * i;
IntPtr currentVarPtr = variantArray + (s_variantSize * i);
var currentVar = (Variant*)currentVarPtr;
currentVar->_typeUnion._vt = (ushort)VarEnum.VT_EMPTY;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ internal static object Invoke(IDispatch target, int dispId, object[] args, bool[
{
// !! The arguments should be in REVERSED order!!
int actualIndex = argCount - i - 1;
IntPtr varArgPtr = variantArgArray + s_variantSize * actualIndex;
IntPtr varArgPtr = variantArgArray + (s_variantSize * actualIndex);

// If need to pass by ref, create a by-ref variant
if (byRef != null && byRef[i])
Expand All @@ -169,7 +169,7 @@ internal static object Invoke(IDispatch target, int dispId, object[] args, bool[
}

// Create a VARIANT that the by-ref VARIANT points to
IntPtr tmpVarPtr = tmpVariants + s_variantSize * refIndex;
IntPtr tmpVarPtr = tmpVariants + (s_variantSize * refIndex);
Marshal.GetNativeVariantForObject(args[i], tmpVarPtr);

// Create the by-ref VARIANT
Expand Down Expand Up @@ -266,7 +266,7 @@ internal static object Invoke(IDispatch target, int dispId, object[] args, bool[
// If need to pass by ref, back propagate
if (byRef != null && byRef[i])
{
args[i] = Marshal.GetObjectForNativeVariant(variantArgArray + s_variantSize * actualIndex);
args[i] = Marshal.GetObjectForNativeVariant(variantArgArray + (s_variantSize * actualIndex));
}
}
}
Expand All @@ -280,7 +280,7 @@ internal static object Invoke(IDispatch target, int dispId, object[] args, bool[
{
for (int i = 0; i < argCount; i++)
{
VariantClear(variantArgArray + s_variantSize * i);
VariantClear(variantArgArray + (s_variantSize * i));
}

Marshal.FreeCoTaskMem(variantArgArray);
Expand All @@ -297,7 +297,7 @@ internal static object Invoke(IDispatch target, int dispId, object[] args, bool[
{
for (int i = 0; i < refCount; i++)
{
VariantClear(tmpVariants + s_variantSize * i);
VariantClear(tmpVariants + (s_variantSize * i));
}

Marshal.FreeCoTaskMem(tmpVariants);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2564,8 +2564,8 @@ private int ValidateParameterSets(bool prePipelineInput, bool setDefault)
// If the valid parameter set is the default parameter set, or if the default
// parameter set has been defined and one of the valid parameter sets is
// the default parameter set, then use the default parameter set.
else if (!prePipelineInput &&
validSetIsDefault ||
else if ((!prePipelineInput &&
validSetIsDefault) ||
(hasDefaultSetDefined && (_currentParameterSetFlag & defaultParameterSetFlag) != 0))
{
// NTRAID#Windows Out Of Band Releases-2006/02/14-928660-JonN
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/CommandSearcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,8 @@ private bool ShouldSkipCommandResolutionForConstrainedLanguage(CommandInfo? resu
{
foreach (CmdletInfo cmdlet in cmdletList)
{
if (cmdletMatcher != null &&
cmdletMatcher.IsMatch(cmdlet.Name) ||
if ((cmdletMatcher != null &&
cmdletMatcher.IsMatch(cmdlet.Name)) ||
(_commandResolutionOptions.HasFlag(SearchResolutionOptions.FuzzyMatch) &&
FuzzyMatcher.IsFuzzyMatch(cmdlet.Name, _commandName)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ internal CompiledCommandParameter(RuntimeDefinedParameter runtimeDefinedParamete
// and disabled parameter attributes. We should ignore those attributes.
// When processing non-dynamic parameters, the experimental attributes and disabled parameter
// attributes have already been filtered out when constructing the RuntimeDefinedParameter.
if (attribute is ExperimentalAttribute || attribute is ParameterAttribute param && param.ToHide)
if (attribute is ExperimentalAttribute || (attribute is ParameterAttribute param && param.ToHide))
{
continue;
}
Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4331,7 +4331,7 @@ public override int GetHashCode()
{
// To prevent to/from == from/to, multiply and add rather than use
// an operation that won't overflow, like bitwise xor.
return from.GetHashCode() + 37 * to.GetHashCode();
return from.GetHashCode() + (37 * to.GetHashCode());
}
}

Expand Down Expand Up @@ -5180,8 +5180,8 @@ private static bool ProjectedTypeMatchesTargetType(Type sourceType, Type targetT
var sourceTypeDef = sourceType.GetGenericTypeDefinition();
bool isOutParameter = matchContext == TypeMatchingContext.OutParameterType;

if (targetType.IsByRef && sourceTypeDef == (isOutParameter ? typeof(PSOutParameter<>) : typeof(PSReference<>)) ||
targetType.IsPointer && sourceTypeDef == typeof(PSPointer<>))
if ((targetType.IsByRef && sourceTypeDef == (isOutParameter ? typeof(PSOutParameter<>) : typeof(PSReference<>))) ||
(targetType.IsPointer && sourceTypeDef == typeof(PSPointer<>)))
{
// For ref/out parameter types and pointer types, the element types need to match exactly.
if (targetType.GetElementType() == sourceType.GenericTypeArguments[0])
Expand All @@ -5195,8 +5195,8 @@ private static bool ProjectedTypeMatchesTargetType(Type sourceType, Type targetT
}

if (targetType == sourceType ||
targetType == typeof(void) && sourceType == typeof(VOID) ||
targetType == typeof(TypedReference) && sourceType == typeof(PSTypedReference))
(targetType == typeof(void) && sourceType == typeof(VOID)) ||
(targetType == typeof(TypedReference) && sourceType == typeof(PSTypedReference)))
{
matchExactly = true;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,17 +1627,17 @@ public int GetHashCode(PSModuleInfo obj)
result = 23;
if (obj.Name != null)
{
result = result * 17 + obj.Name.GetHashCode();
result = (result * 17) + obj.Name.GetHashCode();
}

if (obj.Guid != Guid.Empty)
{
result = result * 17 + obj.Guid.GetHashCode();
result = (result * 17) + obj.Guid.GetHashCode();
}

if (obj.Version != null)
{
result = result * 17 + obj.Version.GetHashCode();
result = (result * 17) + obj.Version.GetHashCode();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ internal void ThrowIfWriteNotPermitted(bool needsToWriteToPipeline)
{
if (this.PipelineProcessor == null
|| _thisCommand != this.PipelineProcessor._permittedToWrite
|| needsToWriteToPipeline && !this.PipelineProcessor._permittedToWriteToPipeline
|| (needsToWriteToPipeline && !this.PipelineProcessor._permittedToWriteToPipeline)
|| Thread.CurrentThread != this.PipelineProcessor._permittedToWriteThread
)
{
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 @@ -1996,8 +1996,8 @@ public override int GetHashCode()
{
int result = 61;

result = result * 397 + (MethodTargetType != null ? MethodTargetType.GetHashCode() : 0);
result = result * 397 + ParameterTypes.SequenceGetHashCode();
result = (result * 397) + (MethodTargetType != null ? MethodTargetType.GetHashCode() : 0);
result = (result * 397) + ParameterTypes.SequenceGetHashCode();

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private void AppendOneNativeArgument(ExecutionContext context, object obj, Array
{
IEnumerator list = LanguagePrimitives.GetEnumerator(obj);

Diagnostics.Assert((argArrayAst == null) || obj is object[] && ((object[])obj).Length == argArrayAst.Elements.Count, "array argument and ArrayLiteralAst differ in number of elements");
Diagnostics.Assert((argArrayAst == null) || (obj is object[] && ((object[])obj).Length == argArrayAst.Elements.Count), "array argument and ArrayLiteralAst differ in number of elements");

int currentElement = -1;
string separator = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ private static bool TryParseVersion(string version, ref VersionResult result)
return false;
}

if (preLabel != null && !Regex.IsMatch(preLabel, LabelUnitRegEx) ||
if ((preLabel != null && !Regex.IsMatch(preLabel, LabelUnitRegEx)) ||
(buildLabel != null && !Regex.IsMatch(buildLabel, LabelUnitRegEx)))
{
result.SetFailure(ParseFailureKind.FormatException);
Expand Down
Loading