Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private static unsafe int BCryptEncryptRsa(
BCryptEncryptFlags dwFlags)
{
// BCryptEncrypt does not accept null/0, only non-null/0.
ReadOnlySpan<byte> notNull = stackalloc byte[1];
Comment thread
EgorBo marked this conversation as resolved.
ReadOnlySpan<byte> notNull = [0];
scoped ReadOnlySpan<byte> effectiveSource;

if (source.IsEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ internal static unsafe void NumberToStringFormat<TChar>(ref ValueListBuilder<TCh
// Adjust represents the number of characters over the formatting e.g. format string is "0000" and you are trying to
// format 100000 (6 digits). Means adjust will be 2. On the other hand if you are trying to format 10 adjust will be
// -2 and we'll need to fixup these digits with 0 padding if we have 0 formatting as in this example.
Span<int> thousandsSepPos = stackalloc int[4];
Span<int> thousandsSepPos = [0, 0, 0, 0];
int thousandsSepCtr = -1;

if (thousandSeps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private SqlDecimal(bool _)
_data4 = s_uiZero;
}

public unsafe SqlDecimal(decimal value)
public SqlDecimal(decimal value)
{
// set the null bit
_bStatus = s_bNotNull;
Expand All @@ -490,7 +490,7 @@ public unsafe SqlDecimal(decimal value)
// m_data1 = *pInt++; // lo part
// m_data2 = *pInt++; // mid part

Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.GetBits(value, bits);
uint sgnscl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public string DisplayName
/// - '|a000b421-5d183ab6.1.8e2d4c28_' - Id of the grand child activity. It was started in another process and ends with '_'<para />
/// 'a000b421-5d183ab6' is a <see cref="RootId"/> for the first Activity and all its children
/// </example>
public unsafe string? Id
public string? Id
{
get
{
Expand All @@ -243,7 +243,7 @@ public unsafe string? Id
if (_id == null && _spanId != null)
{
// Convert flags to binary.
Span<char> flagsChars = stackalloc char[2];
Span<char> flagsChars = ['\0', '\0'];
HexConverter.ToCharsBuffer((byte)((~ActivityTraceFlagsIsSet) & _w3CIdFlags), flagsChars, 0, HexConverter.Casing.Lower);
string id =
#if NET
Expand All @@ -266,7 +266,7 @@ public unsafe string? Id
/// <para/>
/// See <see href="https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.DiagnosticSource/src/ActivityUserGuide.md#id-format"/> for more details
/// </summary>
public unsafe string? ParentId
public string? ParentId
{
get
{
Expand All @@ -275,7 +275,7 @@ public unsafe string? ParentId
{
if (_parentSpanId != null)
{
Span<char> flagsChars = stackalloc char[2];
Span<char> flagsChars = ['\0', '\0'];
HexConverter.ToCharsBuffer((byte)((~ActivityTraceFlagsIsSet) & _parentTraceFlags), flagsChars, 0, HexConverter.Casing.Lower);
string parentId =
#if NET
Expand Down Expand Up @@ -2019,12 +2019,12 @@ public override int GetHashCode()
/// This is exposed as CreateFromUtf8String, but we are modifying fields, so the code needs to be in a constructor.
/// </summary>
/// <param name="idData"></param>
private unsafe ActivityTraceId(ReadOnlySpan<byte> idData)
private ActivityTraceId(ReadOnlySpan<byte> idData)
{
if (idData.Length != 32)
throw new ArgumentOutOfRangeException(nameof(idData));

Span<ulong> span = stackalloc ulong[2];
Span<ulong> span = [0, 0];

if (!Utf8Parser.TryParse(idData.Slice(0, 16), out span[0], out _, 'x'))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal static class DecimalHelpers
/// deconstructs a decimal value into its signed integral component and negative base-10 exponent
public static void Deconstruct(decimal value, out decimal mantissa, out byte scale)
{
Span<int> buf = stackalloc int[4];
Span<int> buf = [0, 0, 0, 0];
CborHelpers.GetBitsFromDecimal(value, buf);

int flags = buf[3];
Expand All @@ -154,7 +154,7 @@ public static void Deconstruct(decimal value, out decimal mantissa, out byte sca
/// reconstructs a decimal value out of a signed integral component and a negative base-10 exponent
private static decimal ReconstructFromNegativeScale(decimal mantissa, byte scale)
{
Span<int> buf = stackalloc int[4];
Span<int> buf = [0, 0, 0, 0];
CborHelpers.GetBitsFromDecimal(mantissa, buf);

int flags = buf[3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ public override int EndRead(IAsyncResult asyncResult)
/// <exception cref="InvalidDataException">The data is in an invalid format.</exception>
/// <exception cref="ObjectDisposedException">The stream is disposed.</exception>
/// <exception cref="IOException">Failed to decompress data from the underlying stream.</exception>
public override unsafe int ReadByte()
public override int ReadByte()
{
Span<byte> singleByte = stackalloc byte[1];
Span<byte> singleByte = [0];
int bytesRead = Read(singleByte);
return bytesRead > 0 ? singleByte[0] : -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public override int Read(byte[] buffer, int offset, int count)
return ReadInternal(new Span<byte>(buffer, offset, count));
}

public override unsafe int ReadByte()
public override int ReadByte()
{
Span<byte> oneByte = stackalloc byte[1];
Span<byte> oneByte = [0];
return ReadInternal(oneByte) == 0 ? -1 : oneByte[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,9 @@ internal static void EmitArray(this ILGenerator il, Type arrayType)

#region Support for emitting constants

private static unsafe void EmitDecimal(this ILGenerator il, decimal value)
private static void EmitDecimal(this ILGenerator il, decimal value)
{
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.GetBits(value, bits);

int scale = (bits[3] & int.MaxValue) >> 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public unsafe Rune ToLower(Rune value)
// Change span to lower and convert to rune
if (valueChars.Length == 2)
{
Span<char> lowerChars = stackalloc char[2];
Span<char> lowerChars = ['\0', '\0'];
ToLower(valueChars, lowerChars);
return new Rune(lowerChars[0], lowerChars[1]);
}
Expand All @@ -525,7 +525,7 @@ public unsafe Rune ToUpper(Rune value)
// Change span to upper and convert to rune
if (valueChars.Length == 2)
{
Span<char> upperChars = stackalloc char[2];
Span<char> upperChars = ['\0', '\0'];
ToUpper(valueChars, upperChars);
return new Rune(upperChars[0], upperChars[1]);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ private static int AddNonLetter(ref StringBuilder result, ref string input, int
return inputIndex;
}

private unsafe int AddTitlecaseLetter(ref StringBuilder result, ref string input, int inputIndex, int charLen)
private int AddTitlecaseLetter(ref StringBuilder result, ref string input, int inputIndex, int charLen)
{
Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddTitlecaseLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");

Expand All @@ -729,7 +729,7 @@ private unsafe int AddTitlecaseLetter(ref StringBuilder result, ref string input
}
else
{
Span<char> dst = stackalloc char[2];
Span<char> dst = ['\0', '\0'];
ChangeCaseToUpper(src, dst);
result.Append(dst);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public unsafe void Write(long position, decimal value)
{
EnsureSafeToWrite(position, sizeof(decimal));

Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.TryGetBits(value, bits, out int intsWritten);
Debug.Assert(intsWritten == 4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ internal static unsafe string EscapeCodeBase(string? codebase)
return result;
}

internal static unsafe void EscapeStringToBuilder(scoped ReadOnlySpan<char> stringToEscape, ref ValueStringBuilder vsb)
internal static void EscapeStringToBuilder(scoped ReadOnlySpan<char> stringToEscape, ref ValueStringBuilder vsb)
{
// Allocate enough stack space to hold any Rune's UTF8 encoding.
Span<byte> utf8Bytes = stackalloc byte[4];
Span<byte> utf8Bytes = [0, 0, 0, 0];

while (!stringToEscape.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ private unsafe string AllocateStringForNameIndex(int index, out int dataOffset)
}
}

private unsafe object? _LoadObjectV1(int pos)
private object? _LoadObjectV1(int pos)
{
Debug.Assert(Monitor.IsEntered(this)); // uses _store

Expand Down Expand Up @@ -602,7 +602,7 @@ private unsafe string AllocateStringForNameIndex(int index, out int dataOffset)
#if RESOURCES_EXTENSIONS
int[] bits = new int[4];
#else
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
#endif
for (int i = 0; i < bits.Length; i++)
bits[i] = _store.ReadInt32();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static unsafe SearchValues<char> Create(params ReadOnlySpan<char> values)
if (IndexOfAnyAsciiSearcher.IsVectorizationSupported && PackedSpanHelpers.PackedIndexOfIsSupported &&
maxInclusive < 128 && values.Length == 4 && minInclusive > 0)
{
Span<char> copy = stackalloc char[4];
Span<char> copy = ['\0', '\0', '\0', '\0'];
values.CopyTo(copy);
copy.Sort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ ref Unsafe.As<char, short>(ref Unsafe.Add(ref MemoryMarshal.GetReference(span),
return result;
}

private static unsafe void SurrogateToUpperNLS(char h, char l, out char hr, out char lr)
private static void SurrogateToUpperNLS(char h, char l, out char hr, out char lr)
{
Debug.Assert(char.IsHighSurrogate(h));
Debug.Assert(char.IsLowSurrogate(l));

ReadOnlySpan<char> chars = [h, l];
Span<char> destination = stackalloc char[2];
Span<char> destination = ['\0', '\0'];

int written = Ordinal.ToUpperOrdinal(chars, destination);
Debug.Assert(written == 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ internal void ClearLeftoverData()
_leftoverByteCount = 0;
}

internal unsafe int DrainLeftoverDataForGetCharCount(ReadOnlySpan<byte> bytes, out int bytesConsumed)
internal int DrainLeftoverDataForGetCharCount(ReadOnlySpan<byte> bytes, out int bytesConsumed)
{
// Quick check: we _should not_ have leftover fallback data from a previous invocation,
// as we'd end up consuming any such data and would corrupt whatever Convert call happens
Expand All @@ -231,7 +231,7 @@ internal unsafe int DrainLeftoverDataForGetCharCount(ReadOnlySpan<byte> bytes, o
// Copy the existing leftover data plus as many bytes as possible of the new incoming data
// into a temporary concated buffer, then get its char count by decoding it.

Span<byte> combinedBuffer = stackalloc byte[4];
Span<byte> combinedBuffer = [0, 0, 0, 0];
combinedBuffer = combinedBuffer.Slice(0, ConcatInto(GetLeftoverData(), bytes, combinedBuffer));
int charCount = 0;

Expand Down Expand Up @@ -275,7 +275,7 @@ internal unsafe int DrainLeftoverDataForGetCharCount(ReadOnlySpan<byte> bytes, o
return charCount;
}

internal unsafe int DrainLeftoverDataForGetChars(ReadOnlySpan<byte> bytes, Span<char> chars, out int bytesConsumed)
internal int DrainLeftoverDataForGetChars(ReadOnlySpan<byte> bytes, Span<char> chars, out int bytesConsumed)
{
// Quick check: we _should not_ have leftover fallback data from a previous invocation,
// as we'd end up consuming any such data and would corrupt whatever Convert call happens
Expand All @@ -287,7 +287,7 @@ internal unsafe int DrainLeftoverDataForGetChars(ReadOnlySpan<byte> bytes, Span<
// Copy the existing leftover data plus as many bytes as possible of the new incoming data
// into a temporary concated buffer, then transcode it from bytes to chars.

Span<byte> combinedBuffer = stackalloc byte[4];
Span<byte> combinedBuffer = [0, 0, 0, 0];
combinedBuffer = combinedBuffer.Slice(0, ConcatInto(GetLeftoverData(), bytes, combinedBuffer));
int charsWritten = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ internal virtual OperationStatus EncodeRune(Rune value, Span<byte> bytes, out in
/// Returns <see langword="false"/> if the <see cref="Rune"/> cannot be represented in the
/// current <see cref="Encoding"/>.
/// </summary>
internal virtual unsafe bool TryGetByteCount(Rune value, out int byteCount)
internal virtual bool TryGetByteCount(Rune value, out int byteCount)
{
// Any production-quality type would override this method and provide a real
// implementation, so we won't provide a base implementation. However, a
// non-shipping slow reference implementation is provided below for convenience.

#if false
Span<byte> bytes = stackalloc byte[4]; // max 4 bytes per input scalar
Span<byte> bytes = [0, 0, 0, 0]; // max 4 bytes per input scalar

OperationStatus opStatus = EncodeRune(value, bytes, out byteCount);
Debug.Assert(opStatus == OperationStatus.Done || opStatus == OperationStatus.InvalidData, "Unexpected return value.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,15 @@ public override void WriteDoubleText(double d)
}
}

public override unsafe void WriteDecimalText(decimal d)
public override void WriteDecimalText(decimal d)
{
if (BitConverter.IsLittleEndian)
{
WriteTextNodeRaw(XmlBinaryNodeType.DecimalText, d);
}
else
{
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.TryGetBits(d, bits, out int intsWritten);
Debug.Assert(intsWritten == 4);

Expand Down Expand Up @@ -946,15 +946,15 @@ public void WriteDoubleArray(ReadOnlySpan<double> items)
}
}

public unsafe void WriteDecimalArray(ReadOnlySpan<decimal> items)
public void WriteDecimalArray(ReadOnlySpan<decimal> items)
{
if (BitConverter.IsLittleEndian)
{
WriteArray(XmlBinaryNodeType.DecimalTextWithEndElement, items.Length, MemoryMarshal.AsBytes(items));
}
else
{
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
WriteArrayInfo(XmlBinaryNodeType.DecimalTextWithEndElement, items.Length);
foreach (ref readonly decimal d in items)
{
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.Uri/src/System/IriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public static bool IsInInclusiveRange(uint value, uint min, uint max)

// IRI normalization for strings containing characters that are not allowed or
// escaped characters that should be unescaped in the context of the specified Uri component.
public static unsafe void EscapeUnescapeIri(ref ValueStringBuilder dest, scoped ReadOnlySpan<char> span, bool isQuery)
public static void EscapeUnescapeIri(ref ValueStringBuilder dest, scoped ReadOnlySpan<char> span, bool isQuery)
{
Span<byte> maxUtf8EncodedSpan = stackalloc byte[4];
Span<byte> maxUtf8EncodedSpan = [0, 0, 0, 0];

for (int i = 0; (uint)i < (uint)span.Length; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.Uri/src/System/UriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ internal static void EscapeString(scoped ReadOnlySpan<char> stringToEscape, ref
}
}

private static unsafe void EscapeStringToBuilder(
private static void EscapeStringToBuilder(
scoped ReadOnlySpan<char> stringToEscape, ref ValueStringBuilder vsb,
SearchValues<char> noEscape, bool checkExistingEscaped)
{
Debug.Assert(!stringToEscape.IsEmpty && !noEscape.Contains(stringToEscape[0]));

// Allocate enough stack space to hold any Rune's UTF8 encoding.
Span<byte> utf8Bytes = stackalloc byte[4];
Span<byte> utf8Bytes = [0, 0, 0, 0];
Comment thread
EgorBo marked this conversation as resolved.

while (!stringToEscape.IsEmpty)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ namespace System.Reflection.Internal
{
internal static class DecimalUtilities
{
public static unsafe int GetScale(this decimal value)
public static int GetScale(this decimal value)
{
#if NET
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.GetBits(value, bits);
return unchecked((byte)(bits[3] >> 16));
#else
return unchecked((byte)(decimal.GetBits(value)[3] >> 16));
#endif
}

public static unsafe void GetBits(this decimal value, out bool isNegative, out byte scale, out uint low, out uint mid, out uint high)
public static void GetBits(this decimal value, out bool isNegative, out byte scale, out uint low, out uint mid, out uint high)
{
#if NET
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.GetBits(value, bits);
#else
int[] bits = decimal.GetBits(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ public BigInteger(double value)
AssertValid();
}

public unsafe BigInteger(decimal value)
public BigInteger(decimal value)
{
// First truncate to get scale to 0 and extract bits
Span<int> bits = stackalloc int[4];
Span<int> bits = [0, 0, 0, 0];
decimal.GetBits(decimal.Truncate(value), bits);

Debug.Assert(bits.Length == 4 && (bits[3] & DecimalScaleFactorMask) == 0);
Expand Down
Loading
Loading