Skip to content

Commit

Permalink
Replace Span<T>.Fill(0) with Span<T>.Clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
turbedi committed Apr 6, 2020
1 parent 1c64d21 commit 9aabaf3
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions src/SharpCompress/Archives/AbstractWritableArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ IArchiveEntry IWritableArchive.AddEntry(string key, Stream source, bool closeStr
public TEntry AddEntry(string key, Stream source, bool closeStream,
long size = 0, DateTime? modified = null)
{
if (key.StartsWith('/')
|| key.StartsWith('\\'))
if (key.StartsWith("/")
|| key.StartsWith("\\"))
{
key = key.Substring(1);
}
Expand All @@ -103,7 +103,7 @@ private bool DoesKeyMatchExisting(string key)
foreach (var path in Entries.Select(x => x.Key))
{
var p = path.Replace('/', '\\');
if (p.StartsWith('\\'))
if (p.StartsWith("\\"))
{
p = p.Substring(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Tar/Headers/TarHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private static void WriteStringBytes(ReadOnlySpan<byte> name, Span<byte> buffer,
{
name.CopyTo(buffer);
int i = Math.Min(length, name.Length);
buffer.Slice(i, length - i).Fill(0);
buffer.Slice(i, length - i).Clear();
}

private static void WriteStringBytes(string name, byte[] buffer, int offset, int length)
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ internal bool IsDirectory
{
get
{
if (Name.EndsWith('/'))
if (Name.EndsWith("/"))
{
return true;
}

//.NET Framework 4.5 : System.IO.Compression::CreateFromDirectory() probably writes backslashes to headers
return CompressedSize == 0
&& UncompressedSize == 0
&& Name.EndsWith('\\');
&& Name.EndsWith("\\");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/SharpCompress/Compressors/Deflate/GZipStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,16 @@ public string FileName
{
return;
}
if (_fileName.Contains('/'))
if (_fileName.Contains("/"))
{
_fileName = _fileName.Replace('/', '\\');
}
if (_fileName.EndsWith('\\'))
if (_fileName.EndsWith("\\"))
{
throw new InvalidOperationException("Illegal filename");
}

if (FileName.Contains('\\'))
if (FileName.Contains("\\"))
{
// trim any leading path
int length = _fileName.Length;
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Compressors/PPMd/H/ModelPPM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public ModelPpm()

private void RestartModelRare()
{
new Span<int>(_charMask).Fill(0);
new Span<int>(_charMask).Clear();
SubAlloc.InitSubAllocator();
_initRl = -(_maxOrder < 12 ? _maxOrder : 12) - 1;
int addr = SubAlloc.AllocContext();
Expand Down Expand Up @@ -228,7 +228,7 @@ private void StartModelRare(int maxOrder)
private void ClearMask()
{
_escCount = 1;
new Span<int>(_charMask).Fill(0);
new Span<int>(_charMask).Clear();
}

internal bool DecodeInit(IRarUnpack unpackRead, int escChar)
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Compressors/PPMd/H/SubAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public virtual void DecPText(int dPText)
public virtual void InitSubAllocator()
{
int i, k;
new Span<byte>(_heap, _freeListPos, SizeOfFreeList()).Fill(0);
new Span<byte>(_heap, _freeListPos, SizeOfFreeList()).Clear();

_pText = _heapStart;

Expand Down
8 changes: 4 additions & 4 deletions src/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,13 @@ private void UnpInitData(bool solid)
if (!solid)
{
tablesRead = false;
new Span<int>(oldDist).Fill(0); // memset(oldDist,0,sizeof(OldDist));
new Span<int>(oldDist).Clear(); // memset(oldDist,0,sizeof(OldDist));

oldDistPtr = 0;
lastDist = 0;
lastLength = 0;

new Span<byte>(unpOldTable).Fill(0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
new Span<byte>(unpOldTable).Clear(); // memset(UnpOldTable,0,sizeof(UnpOldTable));

unpPtr = 0;
wrPtr = 0;
Expand Down Expand Up @@ -837,7 +837,7 @@ private bool ReadTables()

if ((bitField & 0x4000) == 0)
{
new Span<byte>(unpOldTable).Fill(0); // memset(UnpOldTable,0,sizeof(UnpOldTable));
new Span<byte>(unpOldTable).Clear(); // memset(UnpOldTable,0,sizeof(UnpOldTable));
}
AddBits(2);

Expand Down Expand Up @@ -1109,7 +1109,7 @@ private bool AddVMCode(int firstByte, List<byte> vmCode, int length)
oldFilterLengths[FiltPos] = StackFilter.BlockLength;

// memset(StackFilter->Prg.InitR,0,sizeof(StackFilter->Prg.InitR));
new Span<int>(StackFilter.Program.InitR).Fill(0);
new Span<int>(StackFilter.Program.InitR).Clear();
StackFilter.Program.InitR[3] = RarVM.VM_GLOBALMEMADDR; // StackFilter->Prg.InitR[3]=VM_GLOBALMEMADDR;
StackFilter.Program.InitR[4] = StackFilter.BlockLength;

Expand Down
8 changes: 4 additions & 4 deletions src/SharpCompress/Compressors/Rar/UnpackV1/Unpack15.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ private void initHuff()
ChSetC[I] = ((~I + 1) & 0xff) << 8;
}

new Span<int>(NToPl).Fill(0); // memset(NToPl,0,sizeof(NToPl));
new Span<int>(NToPlB).Fill(0); // memset(NToPlB,0,sizeof(NToPlB));
new Span<int>(NToPlC).Fill(0); // memset(NToPlC,0,sizeof(NToPlC));
new Span<int>(NToPl).Clear(); // memset(NToPl,0,sizeof(NToPl));
new Span<int>(NToPlB).Clear(); // memset(NToPlB,0,sizeof(NToPlB));
new Span<int>(NToPlC).Clear(); // memset(NToPlC,0,sizeof(NToPlC));
corrHuff(ChSetB, NToPlB);
}

Expand All @@ -670,7 +670,7 @@ private void corrHuff(int[] CharSet, int[] NumToPlace)
// & ~0xff) | I;
}
}
new Span<int>(NumToPlace).Fill(0); // memset(NumToPlace,0,sizeof(NToPl));
new Span<int>(NumToPlace).Clear(); // memset(NumToPlace,0,sizeof(NToPl));
for (I = 6; I >= 0; I--)
{
NumToPlace[I] = (7 - I) * 32;
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private bool ReadTables20()
if (0 == (BitField & 0x4000))
{
// memset(UnpOldTable20,0,sizeof(UnpOldTable20));
new Span<byte>(UnpOldTable20).Fill(0);
new Span<byte>(UnpOldTable20).Clear();
}
AddBits(2);

Expand Down Expand Up @@ -371,7 +371,7 @@ private void unpInitData20(bool Solid)
AudV[3] = new AudioVariables();

// memset(UnpOldTable20,0,sizeof(UnpOldTable20));
new Span<byte>(UnpOldTable20).Fill(0);
new Span<byte>(UnpOldTable20).Clear();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal static void makeDecodeTables(byte[] lenTab, int offset, Decode.Decode d
int i;
long M, N;

new Span<int>(dec.DecodeNum).Fill(0); // memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));
new Span<int>(dec.DecodeNum).Clear(); // memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));

for (i = 0; i < size; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,9 @@ private void InitHuff()
ChSetA[I]=(ushort)I;
ChSetC[I]=(ushort)(((~I+1) & 0xff)<<8);
}
new Span<byte>(NToPl).Fill(0);
new Span<byte>(NToPlB).Fill(0);
new Span<byte>(NToPlC).Fill(0);
new Span<byte>(NToPl).Clear();
new Span<byte>(NToPlB).Clear();
new Span<byte>(NToPlC).Clear();
CorrHuff(ChSetB,NToPlB);
}

Expand All @@ -558,7 +558,7 @@ private void CorrHuff(ushort[] CharSet,byte[] NumToPlace)
for (I=7;I>=0;I--)
for (J=0;J<32;J++)
CharSet[J]=(ushort)((CharSet[J] & ~0xff) | I);
new Span<byte>(NumToPlace, 0, NToPl.Length).Fill(0);
new Span<byte>(NumToPlace, 0, NToPl.Length).Clear();
for (I=6;I>=0;I--)
NumToPlace[I]=(byte)((7-I)*32);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private bool ReadTables20()

if ((BitField & 0x4000) != 0)
{
new Span<byte>(UnpOldTable20).Fill(0);
new Span<byte>(UnpOldTable20).Clear();
}

Inp.addbits(2);
Expand Down Expand Up @@ -363,7 +363,7 @@ private void UnpInitData20(bool Solid)

//memset(AudV,0,sizeof(AudV));
AudV = new AudioVariables[4];
new Span<byte>(UnpOldTable20).Fill(0);
new Span<byte>(UnpOldTable20).Clear();
//memset(MD,0,sizeof(MD));
MD = new DecodeTable[4];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void UnpInitData(bool Solid)
{
if (!Solid)
{
new Span<uint>(OldDist).Fill(0);
new Span<uint>(OldDist).Clear();
OldDistPtr=0;
LastDist=LastLength=0;
// memset(Window,0,MaxWinSize);
Expand Down Expand Up @@ -270,7 +270,7 @@ private void MakeDecodeTables(byte[] LengthTable, int offset, DecodeTable Dec,ui

// Set the entire DecodeNum to zero.
//memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));
new Span<ushort>(Dec.DecodeNum).Fill(0);
new Span<ushort>(Dec.DecodeNum).Clear();

// Initialize not really used entry for zero length code.
Dec.DecodePos[0]=0;
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Crypto/RijndaelEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class RijndaelEngine
57, 75, 221, 124, 132, 151, 162, 253, 28, 36, 108, 180, 199, 82, 246, 1
};

private static ReadOnlySpan<byte> S => new byte[]
private static readonly byte[] S =
{
99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118,
202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192,
Expand All @@ -101,7 +101,7 @@ public class RijndaelEngine
140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22
};

private static ReadOnlySpan<byte> Si => new byte[]
private static readonly byte[] Si =
{
82, 9, 106, 213, 48, 54, 165, 56, 191, 64, 163, 158, 129, 243, 215, 251,
124, 227, 57, 130, 155, 47, 255, 135, 52, 142, 67, 68, 196, 222, 233, 203,
Expand Down

0 comments on commit 9aabaf3

Please sign in to comment.