Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine AsSpan().Slice(...) calls into AsSpan(...) #76799

Merged
merged 1 commit into from
Oct 10, 2022
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
6 changes: 3 additions & 3 deletions src/libraries/Common/src/System/Net/MultiArrayBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@ public void GrowAvailableSpace(int byteCount)
}

byte[]?[] newBlockArray = new byte[]?[blockArraySize];
_blocks.AsSpan().Slice((int)unusedInitialBlocks, (int)usedBlocks).CopyTo(newBlockArray);
_blocks.AsSpan((int)unusedInitialBlocks, (int)usedBlocks).CopyTo(newBlockArray);
_blocks = newBlockArray;
}
else
{
// We can shift the array down to make enough space
_blocks.AsSpan().Slice((int)unusedInitialBlocks, (int)usedBlocks).CopyTo(_blocks);
_blocks.AsSpan((int)unusedInitialBlocks, (int)usedBlocks).CopyTo(_blocks);

// Null out the part of the array left over from the shift, so that we aren't holding references to those blocks.
_blocks.AsSpan().Slice((int)usedBlocks, (int)unusedInitialBlocks).Clear();
_blocks.AsSpan((int)usedBlocks, (int)unusedInitialBlocks).Clear();
}

uint shift = unusedInitialBlocks * BlockSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3007,7 +3007,7 @@ public virtual async Task ZeroByteRead_PerformsZeroByteReadOnUnderlyingStreamWhe

if (FlushGuaranteesAllDataWritten)
{
AssertExtensions.SequenceEqual(data, buffer.AsSpan().Slice(0, bytesRead));
AssertExtensions.SequenceEqual(data, buffer.AsSpan(0, bytesRead));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal ODBC32.SQLRETURN GetDiagnosticField(out string sqlState)
ODBC.TraceODBC(3, "SQLGetDiagFieldW", retcode);
if ((retcode == ODBC32.SQLRETURN.SUCCESS) || (retcode == ODBC32.SQLRETURN.SUCCESS_WITH_INFO))
{
sqlState = new string(buffer.AsSpan().Slice(0, buffer.AsSpan().IndexOf('\0')));
sqlState = new string(buffer.AsSpan(0, buffer.AsSpan().IndexOf('\0')));
}
else
{
Expand All @@ -208,13 +208,13 @@ internal ODBC32.SQLRETURN GetDiagnosticRecord(short record, out string sqlState,

if ((retcode == ODBC32.SQLRETURN.SUCCESS) || (retcode == ODBC32.SQLRETURN.SUCCESS_WITH_INFO))
{
sqlState = new string(buffer.AsSpan().Slice(0, buffer.AsSpan().IndexOf('\0')));
sqlState = new string(buffer.AsSpan(0, buffer.AsSpan().IndexOf('\0')));
}
else
{
sqlState = string.Empty;
}
messageBuilder.Append(new string(message.AsSpan().Slice(0, message.AsSpan().IndexOf('\0'))));
messageBuilder.Append(new string(message.AsSpan(0, message.AsSpan().IndexOf('\0'))));
return retcode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected void RecordMeasurement(T measurement, in TagList tagList)
KeyValuePair<string, object?>[]? tags = tagList.Tags;
if (tags is not null)
{
RecordMeasurement(measurement, tags.AsSpan().Slice(0, tagList.Count));
RecordMeasurement(measurement, tags.AsSpan(0, tagList.Count));
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected void RecordMeasurement(T measurement, KeyValuePair<string, object?> ta
var tags = ts_tags ?? new KeyValuePair<string, object?>[MaxTagsCount];
ts_tags = null;
tags[0] = tag;
RecordMeasurement(measurement, tags.AsSpan().Slice(0, 1));
RecordMeasurement(measurement, tags.AsSpan(0, 1));
ts_tags = tags;
}

Expand All @@ -48,7 +48,7 @@ protected void RecordMeasurement(T measurement, KeyValuePair<string, object?> ta
ts_tags = null;
tags[0] = tag1;
tags[1] = tag2;
RecordMeasurement(measurement, tags.AsSpan().Slice(0, 2));
RecordMeasurement(measurement, tags.AsSpan(0, 2));
ts_tags = tags;
}

Expand All @@ -66,7 +66,7 @@ protected void RecordMeasurement(T measurement, KeyValuePair<string, object?> ta
tags[0] = tag1;
tags[1] = tag2;
tags[2] = tag3;
RecordMeasurement(measurement, tags.AsSpan().Slice(0, 3));
RecordMeasurement(measurement, tags.AsSpan(0, 3));
ts_tags = tags;
}

Expand All @@ -80,7 +80,7 @@ protected void RecordMeasurement(T measurement, in TagList tagList)
KeyValuePair<string, object?>[]? tags = tagList.Tags;
if (tags is not null)
{
RecordMeasurement(measurement, tags.AsSpan().Slice(0, tagList.Count));
RecordMeasurement(measurement, tags.AsSpan(0, tagList.Count));
return;
}

Expand All @@ -104,7 +104,7 @@ protected void RecordMeasurement(T measurement, in TagList tagList)

ts_tags = null;

RecordMeasurement(measurement, tags.AsSpan().Slice(0, tagList.Count));
RecordMeasurement(measurement, tags.AsSpan(0, tagList.Count));

ts_tags = tags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public readonly void CopyTo(Span<KeyValuePair<string, object?>> tags)

if (_overflowTags is not null)
{
_overflowTags.AsSpan().Slice(0, _tagsCount).CopyTo(tags);
_overflowTags.AsSpan(0, _tagsCount).CopyTo(tags);
return;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ public readonly void CopyTo(KeyValuePair<string, object?>[] array, int arrayInde
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
}

CopyTo(array.AsSpan().Slice(arrayIndex));
CopyTo(array.AsSpan(arrayIndex));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static BigInteger CreateBigIntegerFromUnsignedBigEndianBytes(byte[] bigEn
// you can add a zero-byte value to the most significant side of the array.
// Right in this case as it is Big-endian.
var bytesPlusOne = new byte[bigEndianBytes.Length + 1];
bigEndianBytes.CopyTo(bytesPlusOne.AsSpan().Slice(1));
bigEndianBytes.CopyTo(bytesPlusOne.AsSpan(1));
temp = bytesPlusOne;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ public async Task SslStream_RandomSizeWrites_OK(int bufferSize, int readBufferSi
}

Assert.Equal(bufferSize, totalLength);
AssertExtensions.SequenceEqual(dataToCopy.AsSpan(), dataReceived.AsSpan().Slice(0, totalLength));
AssertExtensions.SequenceEqual(dataToCopy.AsSpan(), dataReceived.AsSpan(0, totalLength));
});

await TestConfiguration.WhenAllOrAnyFailedWithTimeout(writer, reader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ public void AcceptAsync_WithReceiveBuffer_Success()

Assert.Equal(acceptBufferDataSize, acceptArgs.BytesTransferred);

AssertExtensions.SequenceEqual(sendBuffer, acceptArgs.Buffer.AsSpan().Slice(0, acceptArgs.BytesTransferred));
AssertExtensions.SequenceEqual(sendBuffer, acceptArgs.Buffer.AsSpan(0, acceptArgs.BytesTransferred));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ internal static unsafe int LastIndexOf(string source, string value, int startInd

if (GlobalizationMode.Invariant)
{
return ignoreCase ? InvariantModeCasing.LastIndexOfIgnoreCase(source.AsSpan().Slice(startIndex, count), value) : LastIndexOf(source, value, startIndex, count);
return ignoreCase ? InvariantModeCasing.LastIndexOfIgnoreCase(source.AsSpan(startIndex, count), value) : LastIndexOf(source, value, startIndex, count);
}

if (GlobalizationMode.UseNls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal static string GetDefaultProvider(int dwType)
}

// check to see if there are upgrades available for the requested CSP
string providerNameString = new string(providerName.AsSpan().Slice(0, providerName.AsSpan().IndexOf('\0')));
string providerNameString = new string(providerName.AsSpan(0, providerName.AsSpan().IndexOf('\0')));
string? wszUpgrade = null;
if (dwType == (int)ProviderType.PROV_RSA_FULL)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ void Test(ref Utf8JsonReader reader)
byte[] buffer = new byte[expectedUtf8Size];
for (int i = 0; i < expectedUtf8Size; i++)
{
JsonTestHelper.AssertThrows<ArgumentException>(ref reader, (ref Utf8JsonReader reader) => reader.CopyString(buffer.AsSpan().Slice(0, i)));
JsonTestHelper.AssertThrows<ArgumentException>(ref reader, (ref Utf8JsonReader reader) => reader.CopyString(buffer.AsSpan(0, i)));
Assert.All(buffer, static b => Assert.Equal(0, b));
}

Expand All @@ -1249,7 +1249,7 @@ void Test(ref Utf8JsonReader reader)
char[] buffer = new char[expectedSize];
for (int i = 0; i < expectedSize; i++)
{
JsonTestHelper.AssertThrows<ArgumentException>(ref reader, (ref Utf8JsonReader reader) => reader.CopyString(buffer.AsSpan().Slice(0, i)));
JsonTestHelper.AssertThrows<ArgumentException>(ref reader, (ref Utf8JsonReader reader) => reader.CopyString(buffer.AsSpan(0, i)));
Assert.All(buffer, static c => Assert.Equal(0, c));
}

Expand Down