Skip to content

Convert CodeBase to collection Expressions #2957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ csharp_using_directive_placement = outside_namespace:warning
csharp_prefer_static_local_function = true:warning
# Primary constructor preferences
csharp_style_prefer_primary_constructors = false:none
# Collection preferences
dotnet_style_prefer_collection_expression = true:error
resharper_use_collection_expression_highlighting =true:error



##########################################
# Unnecessary Code Rules
Expand Down
2 changes: 1 addition & 1 deletion shared-infrastructure
6 changes: 3 additions & 3 deletions src/ImageSharp/Color/Color.WebSafePalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public partial struct Color
/// </summary>
public static ReadOnlyMemory<Color> WebSafePalette => WebSafePaletteLazy.Value;

private static Color[] CreateWebSafePalette() => new[]
{
private static Color[] CreateWebSafePalette() =>
[
AliceBlue,
AntiqueWhite,
Aqua,
Expand Down Expand Up @@ -159,5 +159,5 @@ private static Color[] CreateWebSafePalette() => new[]
WhiteSmoke,
Yellow,
YellowGreen
};
];
}
6 changes: 3 additions & 3 deletions src/ImageSharp/Color/Color.WernerPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public partial struct Color
/// </summary>
public static ReadOnlyMemory<Color> WernerPalette => WernerPaletteLazy.Value;

private static Color[] CreateWernerPalette() => new[]
{
private static Color[] CreateWernerPalette() =>
[
ParseHex("#f1e9cd"),
ParseHex("#f2e7cf"),
ParseHex("#ece6d0"),
Expand Down Expand Up @@ -128,5 +128,5 @@ private static Color[] CreateWernerPalette() => new[]
ParseHex("#9b856b"),
ParseHex("#766051"),
ParseHex("#453b32")
};
];
}
8 changes: 4 additions & 4 deletions src/ImageSharp/Common/Helpers/HexConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ static int FromChar(int c)
{
// Map from an ASCII char to its hex value, e.g. arr['b'] == 11. 0xFF means it's not a hex digit.
// This doesn't actually allocate.
ReadOnlySpan<byte> charToHexLookup = new byte[]
{
ReadOnlySpan<byte> charToHexLookup =
[
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 15
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 31
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 47
Expand All @@ -52,8 +52,8 @@ static int FromChar(int c)
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 207
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 223
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 239
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 255
};
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 255
];

return (uint)c >= (uint)charToHexLookup.Length ? 0xFF : charToHexLookup[c];
}
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Common/InlineArray.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

// <auto-generated />
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Common/InlineArray.tt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp;
<#GenerateInlineArrays();#>

<#+
private static int[] Lengths = new int[] {4, 8, 16 };
private static int[] Lengths = [4, 8, 16 ];

void GenerateInlineArrays()
{
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Compression/Zlib/Adler32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ internal static class Adler32
private const int BlockSize = 1 << 5;

// The C# compiler emits this as a compile-time constant embedded in the PE file.
private static ReadOnlySpan<byte> Tap1Tap2 => new byte[]
{
private static ReadOnlySpan<byte> Tap1Tap2 =>
[
32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, // tap1
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 // tap2
};
];

/// <summary>
/// Calculates the Adler32 checksum with the bytes taken from the span.
Expand Down
10 changes: 5 additions & 5 deletions src/ImageSharp/Compression/Zlib/DeflaterConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,25 @@ internal static class DeflaterConstants
/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] GOOD_LENGTH = { 0, 4, 4, 4, 4, 8, 8, 8, 32, 32 };
public static int[] GOOD_LENGTH = [0, 4, 4, 4, 4, 8, 8, 8, 32, 32];

/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] MAX_LAZY = { 0, 4, 5, 6, 4, 16, 16, 32, 128, 258 };
public static int[] MAX_LAZY = [0, 4, 5, 6, 4, 16, 16, 32, 128, 258];

/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] NICE_LENGTH = { 0, 8, 16, 32, 16, 32, 128, 128, 258, 258 };
public static int[] NICE_LENGTH = [0, 8, 16, 32, 16, 32, 128, 128, 258, 258];

/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] MAX_CHAIN = { 0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096 };
public static int[] MAX_CHAIN = [0, 4, 8, 32, 16, 32, 128, 256, 1024, 4096];

/// <summary>
/// Internal compression engine constant
/// </summary>
public static int[] COMPR_FUNC = { 0, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
public static int[] COMPR_FUNC = [0, 1, 1, 1, 1, 2, 2, 2, 2, 2];
}
36 changes: 18 additions & 18 deletions src/ImageSharp/Compression/Zlib/DeflaterHuffman.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public DeflaterHuffman(MemoryAllocator memoryAllocator)

// See RFC 1951 3.2.6
// Literal codes
private static readonly short[] StaticLCodes = new short[]
{
private static readonly short[] StaticLCodes =
[
12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252,
2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242,
10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250,
Expand All @@ -97,10 +97,10 @@ public DeflaterHuffman(MemoryAllocator memoryAllocator)
31, 287, 159, 415, 95, 351, 223, 479, 63, 319, 191, 447, 127, 383, 255, 511,
0, 64, 32, 96, 16, 80, 48, 112, 8, 72, 40, 104, 24, 88, 56, 120, 4, 68, 36,
100, 20, 84, 52, 116, 3, 131, 67, 195, 35, 163
};
];

private static ReadOnlySpan<byte> StaticLLength => new byte[]
{
private static ReadOnlySpan<byte> StaticLLength =>
[
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
Expand All @@ -119,34 +119,34 @@ public DeflaterHuffman(MemoryAllocator memoryAllocator)
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8
};
];

// Distance codes and lengths.
private static readonly short[] StaticDCodes = new short[]
{
private static readonly short[] StaticDCodes =
[
0, 16, 8, 24, 4, 20, 12, 28, 2, 18, 10, 26, 6, 22, 14,
30, 1, 17, 9, 25, 5, 21, 13, 29, 3, 19, 11, 27, 7, 23
};
];

private static ReadOnlySpan<byte> StaticDLength => new byte[]
{
private static ReadOnlySpan<byte> StaticDLength =>
[
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5
};
];
#pragma warning restore SA1201 // Elements should appear in the correct order

/// <summary>
/// Gets the lengths of the bit length codes are sent in order of decreasing probability, to avoid transmitting the lengths for unused bit length codes.
/// </summary>
private static ReadOnlySpan<byte> BitLengthOrder => new byte[]
{
private static ReadOnlySpan<byte> BitLengthOrder =>
[
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
};
];

private static ReadOnlySpan<byte> Bit4Reverse => new byte[]
{
private static ReadOnlySpan<byte> Bit4Reverse =>
[
0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15
};
];

/// <summary>
/// Gets the pending buffer to use.
Expand Down
8 changes: 4 additions & 4 deletions src/ImageSharp/Formats/Bmp/BmpConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ internal static class BmpConstants
/// <summary>
/// The list of mimetypes that equate to a bmp.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[]
{
public static readonly IEnumerable<string> MimeTypes =
[
"image/bmp",
"image/x-windows-bmp",
"image/x-win-bitmap"
};
];

/// <summary>
/// The list of file extensions that equate to a bmp.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "bm", "bmp", "dip" };
public static readonly IEnumerable<string> FileExtensions = ["bm", "bmp", "dip"];

/// <summary>
/// Valid magic bytes markers identifying a Bitmap file.
Expand Down
22 changes: 11 additions & 11 deletions src/ImageSharp/Formats/Gif/GifConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,41 +93,41 @@ internal static class GifConstants
/// <summary>
/// The collection of mimetypes that equate to a Gif.
/// </summary>
public static readonly IEnumerable<string> MimeTypes = new[] { "image/gif" };
public static readonly IEnumerable<string> MimeTypes = ["image/gif"];

/// <summary>
/// The collection of file extensions that equate to a Gif.
/// </summary>
public static readonly IEnumerable<string> FileExtensions = new[] { "gif" };
public static readonly IEnumerable<string> FileExtensions = ["gif"];

/// <summary>
/// Gets the ASCII encoded bytes used to identify the GIF file (combining <see cref="FileType"/> and <see cref="FileVersion"/>).
/// </summary>
internal static ReadOnlySpan<byte> MagicNumber => new[]
{
internal static ReadOnlySpan<byte> MagicNumber =>
[
(byte)'G', (byte)'I', (byte)'F',
(byte)'8', (byte)'9', (byte)'a'
};
];

/// <summary>
/// Gets the ASCII encoded application identification bytes (representing <see cref="NetscapeApplicationIdentification"/>).
/// </summary>
internal static ReadOnlySpan<byte> NetscapeApplicationIdentificationBytes => new[]
{
internal static ReadOnlySpan<byte> NetscapeApplicationIdentificationBytes =>
[
(byte)'N', (byte)'E', (byte)'T',
(byte)'S', (byte)'C', (byte)'A',
(byte)'P', (byte)'E',
(byte)'2', (byte)'.', (byte)'0'
};
];

/// <summary>
/// Gets the ASCII encoded application identification bytes.
/// </summary>
internal static ReadOnlySpan<byte> XmpApplicationIdentificationBytes => new[]
{
internal static ReadOnlySpan<byte> XmpApplicationIdentificationBytes =>
[
(byte)'X', (byte)'M', (byte)'P',
(byte)' ', (byte)'D', (byte)'a',
(byte)'t', (byte)'a',
(byte)'X', (byte)'M', (byte)'P'
};
];
}
4 changes: 2 additions & 2 deletions src/ImageSharp/Formats/Gif/LzwEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal sealed class LzwEncoder : IDisposable
/// Mask used when shifting pixel values
/// </summary>
private static readonly int[] Masks =
{
[
0b0,
0b1,
0b11,
Expand All @@ -65,7 +65,7 @@ internal sealed class LzwEncoder : IDisposable
0b11111111111111,
0b111111111111111,
0b1111111111111111
};
];

/// <summary>
/// The maximum number of bits/code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static GifXmpApplicationExtension Read(Stream stream, MemoryAllocator all

// Exclude the "magic trailer", see XMP Specification Part 3, 1.1.2 GIF
int xmpLength = xmpBytes.Length - 256; // 257 - unread 0x0
byte[] buffer = Array.Empty<byte>();
byte[] buffer = [];
if (xmpLength > 0)
{
buffer = new byte[xmpLength];
Expand Down
Loading
Loading