Skip to content

Commit

Permalink
Replace Array<T>.Empty with Array.Empty<T>() (sshnet#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob-Hague authored Jun 6, 2023
1 parent 27976bb commit a4dbf77
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Init()
[TestMethod]
public void ShouldReturnSecondWhenFirstIsEmpty()
{
var first = Array<byte>.Empty;
var first = Array.Empty<byte>();
var second = CreateBuffer(16);

var actual = Extensions.Concat(first, second);
Expand All @@ -47,7 +47,7 @@ public void ShouldReturnSecondWhenFirstIsNull()
public void ShouldReturnFirstWhenSecondIsEmpty()
{
var first = CreateBuffer(16);
var second = Array<byte>.Empty;
var second = Array.Empty<byte>();

var actual = Extensions.Concat(first, second);

Expand Down Expand Up @@ -101,7 +101,7 @@ public void ShouldConcatSecondToFirstWhenBothAreNotEmpty()
[TestCategory("Performance")]
public void Performance_LargeArray_FirstEmpty()
{
var first = Array<byte>.Empty;
var first = Array.Empty<byte>();
var second = CreateBuffer(50000);
const int runs = 10000;

Expand All @@ -115,7 +115,7 @@ public void Performance_LargeArray_FirstEmpty()
public void Performance_LargeArray_SecondEmpty()
{
var first = CreateBuffer(50000);
var second = Array<byte>.Empty;
var second = Array.Empty<byte>();
const int runs = 10000;

Performance(first, second, runs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task ReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqual
public async Task ReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
{
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize, default)).ReturnsAsync(Array<byte>.Empty);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize, default)).ReturnsAsync(Array.Empty<byte>());

var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public async Task SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndR
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence)
.Setup(p => p.RequestReadAsync(_handle, (ulong) _actual, _readBufferSize, default))
.ReturnsAsync(Array<byte>.Empty);
.ReturnsAsync(Array.Empty<byte>());

var buffer = _originalBuffer.Copy();
var actual = await _target.ReadAsync(buffer, 0, buffer.Length);
Expand All @@ -136,7 +136,7 @@ public async Task SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndN
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence)
.Setup(p => p.RequestReadAsync(_handle, (ulong)_actual, _readBufferSize, default))
.ReturnsAsync(Array<byte>.Empty);
.ReturnsAsync(Array.Empty<byte>());
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);

await _target.ReadAsync(new byte[10], 0, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public async Task SubsequentReadShouldReturnAllRemaningBytesFromReadBufferWhenCo
public async Task SubsequentReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
{
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, (ulong)(_serverData.Length), _readBufferSize, default)).ReturnsAsync(Array<byte>.Empty);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestReadAsync(_handle, (ulong)(_serverData.Length), _readBufferSize, default)).ReturnsAsync(Array.Empty<byte>());

var buffer = new byte[_numberOfBytesToWriteToReadBuffer + 1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void ReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsEqualToNumb
public void ReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
{
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize)).Returns(Array<byte>.Empty);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData1Length + _serverData2Length), _readBufferSize)).Returns(Array.Empty<byte>());

var numberOfBytesRemainingInReadBuffer = _serverData1Length + _serverData2Length - _numberOfBytesToRead;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndReturnZ
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence)
.Setup(p => p.RequestRead(_handle, (ulong) _actual, _readBufferSize))
.Returns(Array<byte>.Empty);
.Returns(Array.Empty<byte>());

var buffer = _originalBuffer.Copy();
var actual = _target.Read(buffer, 0, buffer.Length);
Expand All @@ -134,7 +134,7 @@ public void SubsequentReadShouldReadAgainFromCurrentPositionFromServerAndNotUpda
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence)
.Setup(p => p.RequestRead(_handle, (ulong)_actual, _readBufferSize))
.Returns(Array<byte>.Empty);
.Returns(Array.Empty<byte>());
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);

_target.Read(new byte[10], 0, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void SubsequentReadShouldReturnAllRemaningBytesFromReadBufferWhenCountIsE
public void SubsequentReadShouldReturnAllRemaningBytesFromReadBufferAndReadAgainWhenCountIsGreaterThanNumberOfRemainingBytesAndNewReadReturnsZeroBytes()
{
SftpSessionMock.InSequence(MockSequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData.Length), _readBufferSize)).Returns(Array<byte>.Empty);
SftpSessionMock.InSequence(MockSequence).Setup(p => p.RequestRead(_handle, (ulong)(_serverData.Length), _readBufferSize)).Returns(Array.Empty<byte>());

var buffer = new byte[_numberOfBytesToWriteToReadBuffer + 1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void ReadShouldStartFromEndOfStream()
SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(_sequence)
.Setup(p => p.RequestRead(_handle, (uint) _length, _readBufferSize))
.Returns(Array<byte>.Empty);
.Returns(Array.Empty<byte>());

var byteRead = _sftpFileStream.ReadByte();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void ReadShouldStartFromEndOfStream()
SftpSessionMock.InSequence(_sequence).Setup(p => p.IsOpen).Returns(true);
SftpSessionMock.InSequence(_sequence)
.Setup(p => p.RequestRead(_handle, (uint) _length, _readBufferSize))
.Returns(Array<byte>.Empty);
.Returns(Array.Empty<byte>());

var byteRead = _sftpFileStream.ReadByte();

Expand Down
7 changes: 0 additions & 7 deletions src/Renci.SshNet/Common/Array.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Renci.SshNet/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public static byte[] Take(this byte[] value, int offset, int count)

if (count == 0)
{
return Array<byte>.Empty;
return Array.Empty<byte>();
}

if (offset == 0 && value.Length == count)
Expand Down Expand Up @@ -215,7 +215,7 @@ public static byte[] Take(this byte[] value, int count)

if (count == 0)
{
return Array<byte>.Empty;
return Array.Empty<byte>();
}

if (value.Length == count)
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Connection/Socks4Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private static byte[] GetProxyUserBytes(string proxyUser)
{
if (proxyUser == null)
{
return Array<byte>.Empty;
return Array.Empty<byte>();
}

return Encoding.ASCII.GetBytes(proxyUser);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Renci.SshNet.Common;
using System;

namespace Renci.SshNet.Messages.Authentication
{
Expand Down Expand Up @@ -44,8 +44,8 @@ protected override int BufferCapacity
public RequestMessageKeyboardInteractive(ServiceName serviceName, string username)
: base(serviceName, username, "keyboard-interactive")
{
Language = Array<byte>.Empty;
SubMethods = Array<byte>.Empty;
Language = Array.Empty<byte>();
SubMethods = Array.Empty<byte>();
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions src/Renci.SshNet/Messages/Transport/IgnoreMessage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using Renci.SshNet.Abstractions;
using Renci.SshNet.Common;

namespace Renci.SshNet.Messages.Transport
{
Expand All @@ -23,7 +22,7 @@ public class IgnoreMessage : Message
/// </summary>
public IgnoreMessage()
{
Data = Array<byte>.Empty;
Data = Array.Empty<byte>();
}

/// <summary>
Expand Down Expand Up @@ -71,7 +70,7 @@ protected override void LoadData()
if (dataLength > (DataStream.Length - DataStream.Position))
{
DiagnosticAbstraction.Log("SSH_MSG_IGNORE: Length exceeds data bytes, data ignored.");
Data = Array<byte>.Empty;
Data = Array.Empty<byte>();
}
else
{
Expand Down
7 changes: 3 additions & 4 deletions src/Renci.SshNet/Sftp/Responses/SftpNameResponse.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text;

using Renci.SshNet.Common;

namespace Renci.SshNet.Sftp.Responses
{
internal sealed class SftpNameResponse : SftpResponse
Expand All @@ -21,7 +20,7 @@ public override SftpMessageTypes SftpMessageType
public SftpNameResponse(uint protocolVersion, Encoding encoding)
: base(protocolVersion)
{
Files = Array<KeyValuePair<string, SftpFileAttributes>>.Empty;
Files = Array.Empty<KeyValuePair<string, SftpFileAttributes>>();
Encoding = encoding;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Renci.SshNet/Sftp/SftpSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public SftpReadAsyncResult BeginRead(byte[] handle, ulong offset, uint length, A
}
else
{
asyncResult.SetAsCompleted(Array<byte>.Empty, completedSynchronously: false);
asyncResult.SetAsCompleted(Array.Empty<byte>(), completedSynchronously: false);
}
});
SendRequest(request);
Expand Down Expand Up @@ -767,7 +767,7 @@ public byte[] RequestRead(byte[] handle, ulong offset, uint length)
}
else
{
data = Array<byte>.Empty;
data = Array.Empty<byte>();
}

_ = wait.Set();
Expand Down Expand Up @@ -804,7 +804,7 @@ public async Task<byte[]> RequestReadAsync(byte[] handle, ulong offset, uint len
{
if (response.StatusCode == StatusCodes.Eof)
{
_ = tcs.TrySetResult(Array<byte>.Empty);
_ = tcs.TrySetResult(Array.Empty<byte>());
}
else
{
Expand Down

0 comments on commit a4dbf77

Please sign in to comment.