Skip to content

Commit

Permalink
Replace static readonly byte[] fields with static ReadOnlySpan<byte> …
Browse files Browse the repository at this point in the history
…properties

Ref.: dotnet/runtime#33780
  • Loading branch information
turbedi committed Apr 6, 2020
1 parent 4a440e9 commit 1c64d21
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ public static bool IsSevenZipFile(Stream stream)
}
}

private static readonly byte[] SIGNATURE = {(byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C};
private static ReadOnlySpan<byte> SIGNATURE => new byte[] {(byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C};

private static bool SignatureMatch(Stream stream)
{
BinaryReader reader = new BinaryReader(stream);
byte[] signatureBytes = reader.ReadBytes(6);
ReadOnlySpan<byte> signatureBytes = reader.ReadBytes(6);
return signatureBytes.SequenceEqual(SIGNATURE);
}

Expand Down
6 changes: 3 additions & 3 deletions src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal sealed class InflaterManaged
// const tables used in decoding:

// Extra bits for length code 257 - 285.
private static readonly byte[] S_EXTRA_LENGTH_BITS =
private static ReadOnlySpan<byte> S_EXTRA_LENGTH_BITS => new byte[]
{ 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,16 };

// The base length for length code 257 - 285.
Expand All @@ -51,9 +51,9 @@ internal sealed class InflaterManaged
{ 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,32769,49153 };

// code lengths for code length alphabet is stored in following order
private static readonly byte[] S_CODE_ORDER = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
private static ReadOnlySpan<byte> S_CODE_ORDER => new byte[] { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };

private static readonly byte[] S_STATIC_DISTANCE_TREE_TABLE =
private static ReadOnlySpan<byte> S_STATIC_DISTANCE_TREE_TABLE => new byte[]
{
0x00,0x10,0x08,0x18,0x04,0x14,0x0c,0x1c,0x02,0x12,0x0a,0x1a,
0x06,0x16,0x0e,0x1e,0x01,0x11,0x09,0x19,0x05,0x15,0x0d,0x1d,
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Compressors/PPMd/I1/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal partial class Model
0x6051
};

private static readonly byte[] EXPONENTIAL_ESCAPES = {25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2};
private static ReadOnlySpan<byte> EXPONENTIAL_ESCAPES => new byte[] {25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2};

#region Public Methods

Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Compressors/Rar/UnpackV1/Unpack20.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal partial class Unpack
56, 64, 80, 96, 112, 128, 160, 192, 224
};

private static readonly byte[] LBits =
private static ReadOnlySpan<byte> LBits => new byte[]
{
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
4, 5, 5, 5, 5
Expand Down
10 changes: 5 additions & 5 deletions src/SharpCompress/Crypto/RijndaelEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class RijndaelEngine

private static readonly int MAXKC = (256 / 4);

private static readonly byte[] Logtable =
private static ReadOnlySpan<byte> Logtable => new byte[]
{
0, 0, 25, 1, 50, 2, 26, 198,
75, 199, 27, 104, 51, 238, 223, 3,
Expand Down Expand Up @@ -45,7 +45,7 @@ public class RijndaelEngine
13, 99, 140, 128, 192, 247, 112, 7
};

private static readonly byte[] Alogtable =
private static ReadOnlySpan<byte> Alogtable => new byte[]
{
0, 3, 5, 15, 17, 51, 85, 255, 26, 46, 114, 150, 161, 248, 19, 53,
95, 225, 56, 72, 216, 115, 149, 164, 247, 2, 6, 10, 30, 34, 102, 170,
Expand Down 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 readonly byte[] S =
private static ReadOnlySpan<byte> S => new byte[]
{
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 readonly byte[] Si =
private static ReadOnlySpan<byte> Si => new byte[]
{
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 All @@ -121,7 +121,7 @@ public class RijndaelEngine
23, 43, 4, 126, 186, 119, 214, 38, 225, 105, 20, 99, 85, 33, 12, 125
};

private static readonly byte[] rcon =
private static ReadOnlySpan<byte> rcon => new byte[]
{
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91
Expand Down

0 comments on commit 1c64d21

Please sign in to comment.