Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion src/Common/src/System/Numerics/Hashing/HashHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ public static int Combine(int h1, int h2)
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Common/tests/System/Buffers/NativeMemoryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Buffers;
using System.Diagnostics;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -55,7 +54,8 @@ public bool IsRetained

public override unsafe MemoryHandle Pin(int elementIndex = 0)
{
if (elementIndex < 0 || elementIndex > _length) throw new ArgumentOutOfRangeException(nameof(elementIndex));
if (elementIndex < 0 || elementIndex > _length)
throw new ArgumentOutOfRangeException(nameof(elementIndex));

lock (this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;

#if !netstandard
using Internal.Runtime.CompilerServices;
#else
using System.Runtime.CompilerServices;
#endif

namespace System.Buffers
{
internal sealed partial class ArrayMemoryPool<T> : MemoryPool<T>
Expand Down
7 changes: 4 additions & 3 deletions src/System.Memory/src/System/Buffers/ArrayMemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ namespace System.Buffers
{
internal sealed partial class ArrayMemoryPool<T> : MemoryPool<T>
{
private const int s_maxBufferSize = int.MaxValue;
public sealed override int MaxBufferSize => s_maxBufferSize;
private const int MaximumBufferSize = int.MaxValue;

public sealed override int MaxBufferSize => MaximumBufferSize;

public sealed override IMemoryOwner<T> Rent(int minimumBufferSize = -1)
{
if (minimumBufferSize == -1)
minimumBufferSize = 1 + (4095 / Unsafe.SizeOf<T>());
else if (((uint)minimumBufferSize) > s_maxBufferSize)
else if (((uint)minimumBufferSize) > MaximumBufferSize)
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.minimumBufferSize);

return new ArrayMemoryPoolBuffer(minimumBufferSize);
Expand Down
2 changes: 1 addition & 1 deletion src/System.Memory/src/System/Buffers/Text/Base64Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan<byte> utf8, Span<byte>
if (srcLength != utf8.Length)
goto InvalidExit;

DoneExit:
DoneExit:
bytesConsumed = sourceIndex;
bytesWritten = destIndex;
return OperationStatus.Done;
Expand Down
4 changes: 2 additions & 2 deletions src/System.Memory/src/System/Buffers/Text/Utf8Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ internal static partial class Utf8Constants
// Invariant formatting uses groups of 3 for each number group separated by commas.
// ex. 1,234,567,890
public const int GroupSize = 3;
public static readonly TimeSpan s_nullUtcOffset = TimeSpan.MinValue; // Utc offsets must range from -14:00 to 14:00 so this is never a valid offset.

public static readonly TimeSpan NullUtcOffset = TimeSpan.MinValue; // Utc offsets must range from -14:00 to 14:00 so this is never a valid offset.

public const int DateTimeMaxUtcOffsetHours = 14; // The UTC offset portion of a TimeSpan or DateTime can be no more than 14 hours and no less than -14 hours.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public static bool TryFormat(bool value, Span<byte> destination, out int bytesWr
return true;
}

BufferTooSmall:
BufferTooSmall:
bytesWritten = 0;
return false;

BadFormat:
BadFormat:
return ThrowHelper.TryFormatThrowFormatException(out bytesWritten);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static bool TryFormatDateTimeG(DateTime value, TimeSpan offset, Span<byt

int bytesRequired = MinimumBytesNeeded;

if (offset != Utf8Constants.s_nullUtcOffset)
if (offset != Utf8Constants.NullUtcOffset)
{
bytesRequired += 7; // Space['+'|'-']hh:mm
}
Expand Down Expand Up @@ -62,7 +62,7 @@ private static bool TryFormatDateTimeG(DateTime value, TimeSpan offset, Span<byt

FormattingHelpers.WriteTwoDecimalDigits((uint)value.Second, destination, 17);

if (offset != Utf8Constants.s_nullUtcOffset)
if (offset != Utf8Constants.NullUtcOffset)
{
byte sign;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static bool TryFormatDateTimeL(DateTime value, Span<byte> destination, o
return false;
}

var dayAbbrev = DayAbbreviationsLowercase[(int)value.DayOfWeek];
uint dayAbbrev = s_dayAbbreviationsLowercase[(int)value.DayOfWeek];

destination[0] = (byte)dayAbbrev;
dayAbbrev >>= 8;
Expand All @@ -35,7 +35,7 @@ private static bool TryFormatDateTimeL(DateTime value, Span<byte> destination, o
FormattingHelpers.WriteTwoDecimalDigits((uint)value.Day, destination, 5);
destination[7] = Utf8Constants.Space;

var monthAbbrev = MonthAbbreviationsLowercase[value.Month - 1];
uint monthAbbrev = s_monthAbbreviationsLowercase[value.Month - 1];
destination[8] = (byte)monthAbbrev;
monthAbbrev >>= 8;
destination[9] = (byte)monthAbbrev;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static bool TryFormatDateTimeO(DateTime value, TimeSpan offset, Span<byt
int bytesRequired = MinimumBytesNeeded;
DateTimeKind kind = DateTimeKind.Local;

if (offset == Utf8Constants.s_nullUtcOffset)
if (offset == Utf8Constants.NullUtcOffset)
{
kind = value.Kind;
if (kind == DateTimeKind.Local)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static bool TryFormatDateTimeR(DateTime value, Span<byte> destination, o
return false;
}

var dayAbbrev = DayAbbreviations[(int)value.DayOfWeek];
uint dayAbbrev = s_dayAbbreviations[(int)value.DayOfWeek];

destination[0] = (byte)dayAbbrev;
dayAbbrev >>= 8;
Expand All @@ -35,7 +35,7 @@ private static bool TryFormatDateTimeR(DateTime value, Span<byte> destination, o
FormattingHelpers.WriteTwoDecimalDigits((uint)value.Day, destination, 5);
destination[7] = Utf8Constants.Space;

var monthAbbrev = MonthAbbreviations[value.Month - 1];
uint monthAbbrev = s_monthAbbreviations[value.Month - 1];
destination[8] = (byte)monthAbbrev;
monthAbbrev >>= 8;
destination[9] = (byte)monthAbbrev;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static partial class Utf8Formatter

// The three-letter abbreviation is packed into a 24-bit unsigned integer
// where the least significant byte represents the first letter.
private static readonly uint[] DayAbbreviations = new uint[]
private static readonly uint[] s_dayAbbreviations = new uint[]
{
'S' + ('u' << 8) + ('n' << 16),
'M' + ('o' << 8) + ('n' << 16),
Expand All @@ -30,7 +30,7 @@ public static partial class Utf8Formatter
'S' + ('a' << 8) + ('t' << 16),
};

private static readonly uint[] DayAbbreviationsLowercase = new uint[]
private static readonly uint[] s_dayAbbreviationsLowercase = new uint[]
{
's' + ('u' << 8) + ('n' << 16),
'm' + ('o' << 8) + ('n' << 16),
Expand All @@ -41,7 +41,7 @@ public static partial class Utf8Formatter
's' + ('a' << 8) + ('t' << 16)
};

private static readonly uint[] MonthAbbreviations = new uint[]
private static readonly uint[] s_monthAbbreviations = new uint[]
{
'J' + ('a' << 8) + ('n' << 16),
'F' + ('e' << 8) + ('b' << 16),
Expand All @@ -57,7 +57,7 @@ public static partial class Utf8Formatter
'D' + ('e' << 8) + ('c' << 16),
};

private static readonly uint[] MonthAbbreviationsLowercase = new uint[]
private static readonly uint[] s_monthAbbreviationsLowercase = new uint[]
{
'j' + ('a' << 8) + ('n' << 16),
'f' + ('e' << 8) + ('b' << 16),
Expand Down Expand Up @@ -97,7 +97,7 @@ public static partial class Utf8Formatter
/// </exceptions>
public static bool TryFormat(DateTimeOffset value, Span<byte> destination, out int bytesWritten, StandardFormat format = default)
{
TimeSpan offset = Utf8Constants.s_nullUtcOffset;
TimeSpan offset = Utf8Constants.NullUtcOffset;
char symbol = format.Symbol;
if (format.IsDefault)
{
Expand Down Expand Up @@ -158,10 +158,10 @@ public static bool TryFormat(DateTime value, Span<byte> destination, out int byt
return TryFormatDateTimeL(value, destination, out bytesWritten);

case 'O':
return TryFormatDateTimeO(value, Utf8Constants.s_nullUtcOffset, destination, out bytesWritten);
return TryFormatDateTimeO(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten);

case 'G':
return TryFormatDateTimeG(value, Utf8Constants.s_nullUtcOffset, destination, out bytesWritten);
return TryFormatDateTimeG(value, Utf8Constants.NullUtcOffset, destination, out bytesWritten);

default:
return ThrowHelper.TryFormatThrowFormatException(out bytesWritten);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace System.Buffers.Text
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static bool TryFormatInt64Default(long value, Span<byte> destination, ou
{
return TryFormatUInt32SingleDigit((uint)value, destination, out bytesWritten);
}

if (IntPtr.Size == 8) // x64
{
return TryFormatInt64MultipleDigits(value, destination, out bytesWritten);
Expand All @@ -34,13 +34,13 @@ private static bool TryFormatInt64Default(long value, Span<byte> destination, ou
{
if (value <= (long)Utf8Constants.BillionMaxUIntValue && value >= -(long)Utf8Constants.BillionMaxUIntValue)
{
return value < 0 ?
return value < 0 ?
TryFormatInt64MoreThanNegativeBillionMaxUInt(-value, destination, out bytesWritten) :
TryFormatUInt64LessThanBillionMaxUInt((ulong)value, destination, out bytesWritten);
TryFormatUInt64LessThanBillionMaxUInt((ulong)value, destination, out bytesWritten);
}
else
{
return value < 0 ?
return value < 0 ?
TryFormatInt64LessThanNegativeBillionMaxUInt(-value, destination, out bytesWritten) :
TryFormatUInt64MoreThanBillionMaxUInt((ulong)value, destination, out bytesWritten);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static bool TryFormat(TimeSpan value, Span<byte> destination, out int byt
ticks = -ticks;
if (ticks < 0)
{
Debug.Assert(ticks == Int64.MinValue /* -9223372036854775808 */);
Debug.Assert(ticks == long.MinValue /* -9223372036854775808 */);

// We computed these ahead of time; they're straight from the decimal representation of Int64.MinValue.
fraction = 4775808;
Expand All @@ -75,7 +75,7 @@ public static bool TryFormat(TimeSpan value, Span<byte> destination, out int byt
fraction = (uint)fraction64;
}

AfterComputeFraction:
AfterComputeFraction:

int fractionDigits = 0;
if (symbol == 'c')
Expand Down Expand Up @@ -131,7 +131,7 @@ public static bool TryFormat(TimeSpan value, Span<byte> destination, out int byt
Debug.Assert(minutes < 60);

// At this point, we can switch over to 32-bit divmod since the data has shrunk far enough.
Debug.Assert(totalHoursRemaining <= UInt32.MaxValue);
Debug.Assert(totalHoursRemaining <= uint.MaxValue);

uint days = 0;
uint hours = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Personally, I don't think we need go out of our way to remove using System.Diagnostics. Encouraging the use of assertions by removing friction from its use is more valuable than removing every bit of white-font from the IDE.


namespace System.Buffers.Text
{
public static partial class Utf8Parser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static bool TryCreateDateTime(int year, int month, int day, int hour, in
return true;
}

private static readonly int[] s_daysToMonth365 = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
private static readonly int[] s_daysToMonth366 = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};
private static readonly int[] s_daysToMonth365 = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
private static readonly int[] s_daysToMonth366 = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static bool TryParse(ReadOnlySpan<byte> source, out float value, out int
return true;
}

return TryParseAsSpecialFloatingPoint<float>(source, float.PositiveInfinity, float.NegativeInfinity, float.NaN, out value, out bytesConsumed);
return TryParseAsSpecialFloatingPoint(source, float.PositiveInfinity, float.NegativeInfinity, float.NaN, out value, out bytesConsumed);
}

/// <summary>
Expand Down Expand Up @@ -68,7 +68,7 @@ public static bool TryParse(ReadOnlySpan<byte> source, out double value, out int
if (TryParseNormalAsFloatingPoint(source, out value, out bytesConsumed, standardFormat))
return true;

return TryParseAsSpecialFloatingPoint<double>(source, double.PositiveInfinity, double.NegativeInfinity, double.NaN, out value, out bytesConsumed);
return TryParseAsSpecialFloatingPoint(source, double.PositiveInfinity, double.NegativeInfinity, double.NaN, out value, out bytesConsumed);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The float version of this method specifies the generic type explicitly - they should stay consistent. (And I'd prefer you keep it explicit. We don't need to jump to accomodate every time the VS IDE whines that the compiler can figure something out. We don't write source code just for the compiler's sake.)

}

//
Expand Down
Loading