Skip to content

Commit

Permalink
Replace uses of 'new T[0]' with 'Empty.Array<T>'
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy committed Mar 1, 2021
1 parent 66f7aa8 commit f3bb09d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/ICSharpCode.SharpZipLib/Encryption/ZipAESTransform.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Security.Cryptography;
using ICSharpCode.SharpZipLib.Core;

namespace ICSharpCode.SharpZipLib.Encryption
{
Expand Down Expand Up @@ -163,7 +164,7 @@ public byte[] TransformFinalBlock(byte[] inputBuffer, int inputOffset, int input
{
throw new NotImplementedException("TransformFinalBlock is not implemented and inputCount is greater than 0");
}
return new byte[0];
return Empty.Array<byte>();
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/ICSharpCode.SharpZipLib/Tar/TarEntry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text;
using ICSharpCode.SharpZipLib.Core;

namespace ICSharpCode.SharpZipLib.Tar
{
Expand Down Expand Up @@ -465,7 +466,7 @@ public TarEntry[] GetDirectoryEntries()
{
if ((file == null) || !Directory.Exists(file))
{
return new TarEntry[0];
return Empty.Array<TarEntry>();
}

string[] list = Directory.GetFileSystemEntries(file);
Expand Down
5 changes: 3 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Core;

namespace ICSharpCode.SharpZipLib.Zip
{
Expand Down Expand Up @@ -521,7 +522,7 @@ public ZipExtraData(byte[] data)
{
if (data == null)
{
_data = new byte[0];
_data = Empty.Array<byte>();
}
else
{
Expand Down Expand Up @@ -552,7 +553,7 @@ public void Clear()
{
if ((_data == null) || (_data.Length != 0))
{
_data = new byte[0];
_data = Empty.Array<byte>();
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public ZipFile(Stream stream, bool leaveOpen)
}
else
{
entries_ = new ZipEntry[0];
entries_ = Empty.Array<ZipEntry>();
isNewArchive_ = true;
}
}
Expand All @@ -549,7 +549,7 @@ public ZipFile(Stream stream, bool leaveOpen)
/// </summary>
internal ZipFile()
{
entries_ = new ZipEntry[0];
entries_ = Empty.Array<ZipEntry>();
isNewArchive_ = true;
}

Expand Down Expand Up @@ -2338,7 +2338,7 @@ private int WriteCentralDirectoryHeader(ZipEntry entry)
baseStream_.Write(centralExtraData, 0, centralExtraData.Length);
}

byte[] rawComment = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : new byte[0];
byte[] rawComment = (entry.Comment != null) ? Encoding.ASCII.GetBytes(entry.Comment) : Empty.Array<byte>();

if (rawComment.Length > 0)
{
Expand Down Expand Up @@ -3347,7 +3347,7 @@ private void DisposeInternal(bool disposing)
if (!isDisposed_)
{
isDisposed_ = true;
entries_ = new ZipEntry[0];
entries_ = Empty.Array<ZipEntry>();

if (IsStreamOwner && (baseStream_ != null))
{
Expand Down
4 changes: 2 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipOutputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public override void Finish()
byte[] entryComment =
(entry.Comment != null) ?
ZipStrings.ConvertToArray(entry.Flags, entry.Comment) :
new byte[0];
Empty.Array<byte>();

if (entryComment.Length > 0xffff)
{
Expand Down Expand Up @@ -987,7 +987,7 @@ public override void Flush()
/// <summary>
/// Comment for the entire archive recorded in central header.
/// </summary>
private byte[] zipComment = new byte[0];
private byte[] zipComment = Empty.Array<byte>();

/// <summary>
/// Flag indicating that header patching is required for the current entry.
Expand Down
5 changes: 3 additions & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipStrings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text;
using ICSharpCode.SharpZipLib.Core;

namespace ICSharpCode.SharpZipLib.Zip
{
Expand Down Expand Up @@ -174,7 +175,7 @@ public static string ConvertToStringExt(int flags, byte[] data)
/// <returns>Converted array</returns>
public static byte[] ConvertToArray(string str)
=> str == null
? new byte[0]
? Empty.Array<byte>()
: Encoding.GetEncoding(CodePage).GetBytes(str);

/// <summary>
Expand All @@ -187,7 +188,7 @@ public static byte[] ConvertToArray(string str)
/// <returns>Converted array</returns>
public static byte[] ConvertToArray(int flags, string str)
=> (string.IsNullOrEmpty(str))
? new byte[0]
? Empty.Array<byte>()
: EncodingFromFlag(flags).GetBytes(str);
}
}

0 comments on commit f3bb09d

Please sign in to comment.