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 @@ -540,7 +540,7 @@ public async Task<byte[]> ReadBodyAsync(bool expectEndOfStream = false)
byte[] newBuffer = new byte[body.Length + dataFrame.Data.Length];

body.CopyTo(newBuffer, 0);
dataFrame.Data.Span.CopyTo(newBuffer.AsSpan().Slice(body.Length));
dataFrame.Data.Span.CopyTo(newBuffer.AsSpan(body.Length));
body= newBuffer;
}
}
Expand Down Expand Up @@ -764,7 +764,7 @@ public async Task SendResponseHeadersAsync(int streamId, bool endStream = true,
flags |= FrameFlags.EndStream;
}

HeadersFrame headersFrame = new HeadersFrame(headerBlock.AsMemory().Slice(0, bytesGenerated), flags, 0, 0, 0, streamId);
HeadersFrame headersFrame = new HeadersFrame(headerBlock.AsMemory(0, bytesGenerated), flags, 0, 0, 0, streamId);
await WriteFrameAsync(headersFrame).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void ResetColor()

private void WriteToConsole(string message, int startIndex, int length, ConsoleColor? background, ConsoleColor? foreground)
{
ReadOnlySpan<char> span = message.AsSpan().Slice(startIndex, length);
ReadOnlySpan<char> span = message.AsSpan(startIndex, length);
var colorChanged = SetColor(background, foreground);
#if NETCOREAPP
_textWriter.Write(span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Parse_CheckTimesWrittenToConsole(int numSegments, string message, st
segments.Add(new ConsoleContext() {
BackgroundColor = bg,
ForegroundColor = fg,
Message = message.AsSpan().Slice(startIndex, length).ToString()
Message = message.AsSpan(startIndex, length).ToString()
});
};
var parser = new AnsiParser(onParseWrite);
Expand Down Expand Up @@ -53,7 +53,7 @@ public void Parse_SetBackgroundForegroundAndMessageThenReset_Success(ConsoleColo
segments.Add(new ConsoleContext() {
BackgroundColor = bg,
ForegroundColor = fg,
Message = message.AsSpan().Slice(startIndex, length).ToString()
Message = message.AsSpan(startIndex, length).ToString()
});
};
var parser = new AnsiParser(onParseWrite);
Expand Down Expand Up @@ -91,7 +91,7 @@ public void Parse_MessageWithMultipleColors_ParsedIntoMultipleSegments()
segments.Add(new ConsoleContext() {
BackgroundColor = bg,
ForegroundColor = fg,
Message = message.AsSpan().Slice(startIndex, length).ToString()
Message = message.AsSpan(startIndex, length).ToString()
});
};
var parser = new AnsiParser(onParseWrite);
Expand Down Expand Up @@ -134,7 +134,7 @@ public void Parse_RepeatedColorChange_PicksLastSet()
segments.Add(new ConsoleContext() {
BackgroundColor = bg,
ForegroundColor = fg,
Message = message.AsSpan().Slice(startIndex, length).ToString()
Message = message.AsSpan(startIndex, length).ToString()
});
};
var parser = new AnsiParser(onParseWrite);
Expand Down Expand Up @@ -187,7 +187,7 @@ public void Parse_ValidSupportedOrUnsupportedCodesInMessage_MessageParsedSuccess
segments.Add(new ConsoleContext() {
BackgroundColor = bg,
ForegroundColor = fg,
Message = message.AsSpan().Slice(startIndex, length).ToString()
Message = message.AsSpan(startIndex, length).ToString()
});
};
var parser = new AnsiParser(onParseWrite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Write(string message)
public void OnParseWrite(string message, int startIndex, int length, ConsoleColor? background, ConsoleColor? foreground)
{
var consoleContext = new ConsoleContext();
consoleContext.Message = message.AsSpan().Slice(startIndex, length).ToString();
consoleContext.Message = message.AsSpan(startIndex, length).ToString();

if (background.HasValue)
{
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Memory.Data/tests/BinaryDataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,12 @@ public async Task CanReadPartial()
var length = 4;
var read = new byte[length];
stream.Read(read, 0, length);
Assert.Equal(buffer.AsMemory().Slice(0, length).ToArray(), read.AsMemory().Slice(0, length).ToArray());
Assert.Equal(buffer.AsMemory(0, length).ToArray(), read.AsMemory(0, length).ToArray());

read = new byte[length];
stream.Position = 0;
await stream.ReadAsync(read, 0, length);
Assert.Equal(buffer.AsMemory().Slice(0, length).ToArray(), read.AsMemory().Slice(0, length).ToArray());
Assert.Equal(buffer.AsMemory(0, length).ToArray(), read.AsMemory(0, length).ToArray());

// no-op as we are at end of stream
stream.Read(read, 0, length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ public void Advance(int bytes)
_written += bytes;
}

public Memory<byte> GetMemory(int sizeHint = 0) => _buffer.AsMemory().Slice(_written);
public Memory<byte> GetMemory(int sizeHint = 0) => _buffer.AsMemory(_written);

public Span<byte> GetSpan(int sizeHint) => _buffer.AsSpan().Slice(_written);
public Span<byte> GetSpan(int sizeHint) => _buffer.AsSpan(_written);

public override string ToString()
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Memory/tests/Span/AsSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void GuidArrayAsSpanWithStartAndLength()
{
var arr = new Guid[20];

Span<Guid> slice = arr.AsSpan().Slice(2, 2);
Span<Guid> slice = arr.AsSpan(2, 2);
Guid guid = Guid.NewGuid();
slice[1] = guid;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private static unsafe byte[] CreateSendMessageBuffer(IpHeader ipHeader, IcmpHead
payload.CopyTo(result, offset + icmpHeaderSize);

// offset now still points to beginning of ICMP header.
ushort checksum = ComputeBufferChecksum(result.AsSpan().Slice(offset));
ushort checksum = ComputeBufferChecksum(result.AsSpan(offset));
// Jam the checksum into the buffer.
result[offset + 2] = (byte)(checksum >> 8);
result[offset + 3] = (byte)(checksum & (0xFF));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public async Task LargeDataSentAndReceived()
int totalBytesRead = 0;
while (totalBytesRead < data.Length)
{
int bytesRead = await stream.ReadAsync(buffer.AsMemory().Slice(totalBytesRead));
int bytesRead = await stream.ReadAsync(buffer.AsMemory(totalBytesRead));
Assert.NotEqual(0, bytesRead);
totalBytesRead += bytesRead;
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public async Task LargeDataSentAndReceived()
int totalBytesRead = 0;
while (totalBytesRead < data.Length)
{
int bytesRead = await stream.ReadAsync(buffer.AsMemory().Slice(totalBytesRead));
int bytesRead = await stream.ReadAsync(buffer.AsMemory(totalBytesRead));
Assert.NotEqual(0, bytesRead);
totalBytesRead += bytesRead;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public async Task SerializeAsync(Stream stream, DataSegment segment, Random? ran
{
// length
int numsize = s_encoding.GetBytes(segment.Length.ToString(), _buffer);
await stream.WriteAsync(_buffer.AsMemory().Slice(0, numsize), token);
await stream.WriteAsync(_buffer.AsMemory(0, numsize), token);
stream.WriteByte((byte)',');
// checksum
numsize = s_encoding.GetBytes(segment.Checksum.ToString(), _buffer);
await stream.WriteAsync(_buffer.AsMemory().Slice(0, numsize), token);
await stream.WriteAsync(_buffer.AsMemory(0, numsize), token);
stream.WriteByte((byte)',');
// payload
Memory<byte> source = segment.AsMemory();
Expand Down Expand Up @@ -147,7 +147,7 @@ public DataSegment Deserialize(ReadOnlySequence<byte> buffer)

ReadOnlySequence<byte> lengthBytes = buffer.Slice(0, pos.Value);
int numSize = s_encoding.GetChars(lengthBytes.ToArray(), _charBuffer);
int length = int.Parse(_charBuffer.AsSpan().Slice(0, numSize));
int length = int.Parse(_charBuffer.AsSpan(0, numSize));
buffer = buffer.Slice(buffer.GetPosition(1, pos.Value));

// checksum
Expand All @@ -159,7 +159,7 @@ public DataSegment Deserialize(ReadOnlySequence<byte> buffer)

ReadOnlySequence<byte> checksumBytes = buffer.Slice(0, pos.Value);
numSize = s_encoding.GetChars(checksumBytes.ToArray(), _charBuffer);
ulong checksum = ulong.Parse(_charBuffer.AsSpan().Slice(0, numSize));
ulong checksum = ulong.Parse(_charBuffer.AsSpan(0, numSize));
buffer = buffer.Slice(buffer.GetPosition(1, pos.Value));

// payload
Expand Down Expand Up @@ -285,10 +285,10 @@ Task Callback(ReadOnlySequence<byte> buffer)
return Task.CompletedTask;
}
}

async Task Monitor(CancellationToken token)
{
do
do
{
await Task.Delay(500);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public unsafe void Ctor_SafeHandle_UnknownSocket_Success()

if (nlh.nlmsg_type == NLMSG_ERROR)
{
MemoryMarshal.TryRead<nlmsgerr>(response.AsSpan().Slice(sizeof(nlmsghdr)), out nlmsgerr err);
MemoryMarshal.TryRead<nlmsgerr>(response.AsSpan(sizeof(nlmsghdr)), out nlmsgerr err);
_output.WriteLine("Netlink request failed with {0}", err.error);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SocketDuplicationTests
private const string TestMessage = "test123!";
private static ArraySegment<byte> TestBytes => Encoding.ASCII.GetBytes(TestMessage);
private static string GetMessageString(ArraySegment<byte> data, int count) =>
Encoding.ASCII.GetString(data.AsSpan().Slice(0, count));
Encoding.ASCII.GetString(data.AsSpan(0, count));

[Fact]
public void UseOnlyOverlappedIO_AlwaysFalse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ internal static int GetCalendarsCore(string localeName, bool useUserOverride, Ca
count = count < calendars.Length ? count + 1 : count;
Span<CalendarId> tmpSpan = stackalloc CalendarId[count]; // should be 23 max.
tmpSpan[0] = userOverride;
calendars.AsSpan().Slice(0, count - 1).CopyTo(tmpSpan.Slice(1));
calendars.AsSpan(0, count - 1).CopyTo(tmpSpan.Slice(1));
tmpSpan.CopyTo(calendars);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ private static void LoadAppLocalIcu(string icuSuffixAndVersion)
int indexOfSeparator = icuSuffixAndVersion.IndexOf(':');
if (indexOfSeparator >= 0)
{
icuSuffix = icuSuffixAndVersion.AsSpan().Slice(0, indexOfSeparator);
version = icuSuffixAndVersion.AsSpan().Slice(icuSuffix.Length + 1);
icuSuffix = icuSuffixAndVersion.AsSpan(0, indexOfSeparator);
version = icuSuffixAndVersion.AsSpan(icuSuffix.Length + 1);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Runtime/tests/System/IndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void CollectionTest()
Assert.Equal(i, array[Index.FromStart(i)]);
Assert.Equal(list.Count - i - 1, array[^(i + 1)]);

Assert.Equal(array.AsSpan().Slice(i, array.Length - i).ToArray(), array[i..]);
Assert.Equal(array.AsSpan(i, array.Length - i).ToArray(), array[i..]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Runtime/tests/System/RangeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private class CustomRangeTester : IEquatable<CustomRangeTester>
public CustomRangeTester(int [] data) => _data = data;
public int Length => _data.Length;
public int this[int index] => _data[index];
public CustomRangeTester Slice(int start, int length) => new CustomRangeTester(_data.AsSpan().Slice(start, length).ToArray());
public CustomRangeTester Slice(int start, int length) => new CustomRangeTester(_data.AsSpan(start, length).ToArray());

public int [] Data => _data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static void ReadWithEncryptedContents()
Assert.Equal(Pkcs12ConfidentialityMode.None, authSafe[1].ConfidentialityMode);

Assert.ThrowsAny<CryptographicException>(
() => authSafe[0].Decrypt(loader.Password.AsSpan().Slice(1)));
() => authSafe[0].Decrypt(loader.Password.AsSpan(1)));

Assert.Equal(Pkcs12ConfidentialityMode.Password, authSafe[0].ConfidentialityMode);
authSafe[0].Decrypt(loader.Password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int Main(string[] args)
* SIGN-EXTENDED VALUE TESTS
*/

Span<byte> spanInt16 = BitConverter.IsLittleEndian ? s_bufferLE.AsSpan().Slice(2) : s_bufferBE;
Span<byte> spanInt16 = BitConverter.IsLittleEndian ? s_bufferLE.AsSpan(2) : s_bufferBE;
short swappedInt16 = BinaryPrimitives.ReverseEndianness(MemoryMarshal.Read<short>(spanInt16));
if (swappedInt16 != ConstantUInt16Expected)
{
Expand Down