From 591a0794fe43b8ac6dc9dd70b9745d1c3e792906 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Wed, 12 Oct 2022 16:39:14 +0200 Subject: [PATCH 1/2] feat: Enable 1825 --- .editorconfig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.editorconfig b/.editorconfig index 179491eece..a3f524f8b0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -137,6 +137,9 @@ space_within_single_line_array_initializer_braces = true #Net Analyzer dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed. +#CA1825: Avoid zero-length array allocations +dotnet_diagnostic.CA1825.severity = warning + # Wrapping preferences csharp_wrap_before_ternary_opsigns = false From 543acb1235c6dbed4a7b612b7878214668005f1e Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Wed, 12 Oct 2022 16:39:38 +0200 Subject: [PATCH 2/2] fix: Address CA1825 rule --- .../Media/TextFormatting/Unicode/GraphemeBreak.cs | 2 +- .../Helpers/ColorPickerHelpers.cs | 2 +- .../Remote/HtmlTransport/SimpleWebSocketHttpServer.cs | 2 +- src/Avalonia.FreeDesktop/DBusMenuExporter.cs | 6 +++--- src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Avalonia.Base/Media/TextFormatting/Unicode/GraphemeBreak.cs b/src/Avalonia.Base/Media/TextFormatting/Unicode/GraphemeBreak.cs index 6986b908a1..d0ceba62f4 100644 --- a/src/Avalonia.Base/Media/TextFormatting/Unicode/GraphemeBreak.cs +++ b/src/Avalonia.Base/Media/TextFormatting/Unicode/GraphemeBreak.cs @@ -2,6 +2,6 @@ namespace Avalonia.Media.TextFormatting.Unicode { internal static class GraphemeBreak { - public static byte[] Data => new byte[0]; + public static byte[] Data => System.Array.Empty(); } } diff --git a/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs b/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs index c1904a3c30..381bc42aaa 100644 --- a/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs +++ b/src/Avalonia.Controls.ColorPicker/Helpers/ColorPickerHelpers.cs @@ -49,7 +49,7 @@ namespace Avalonia.Controls.Primitives { if (width == 0 || height == 0) { - return new byte[0]; + return Array.Empty(); } var bitmap = await Task.Run(() => diff --git a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs index 6af21bbcf5..9a872df960 100644 --- a/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs +++ b/src/Avalonia.DesignerSupport/Remote/HtmlTransport/SimpleWebSocketHttpServer.cs @@ -140,7 +140,7 @@ namespace Avalonia.DesignerSupport.Remote.HtmlTransport IsWebsocketRequest = true; if (headers.TryGetValue("Sec-WebSocket-Protocol", out h)) WebSocketProtocols = h.Split(',').Select(x => x.Trim()).ToArray(); - else WebSocketProtocols = new string[0]; + else WebSocketProtocols = Array.Empty(); } } diff --git a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs index c0511420a6..657e324010 100644 --- a/src/Avalonia.FreeDesktop/DBusMenuExporter.cs +++ b/src/Avalonia.FreeDesktop/DBusMenuExporter.cs @@ -340,7 +340,7 @@ namespace Avalonia.FreeDesktop { var id = item == null ? 0 : GetId(item); var props = GetProperties((item, menu), propertyNames); - var children = (depth == 0 || menu == null) ? new object[0] : new object[menu.Items.Count]; + var children = (depth == 0 || menu == null) ? Array.Empty() : new object[menu.Items.Count]; if(menu != null) for (var c = 0; c < children.Length; c++) { @@ -397,7 +397,7 @@ namespace Avalonia.FreeDesktop { foreach (var e in Events) HandleEvent(e.id, e.eventId, e.data, e.timestamp); - return Task.FromResult(new int[0]); + return Task.FromResult(Array.Empty()); } public async Task AboutToShowAsync(int Id) @@ -407,7 +407,7 @@ namespace Avalonia.FreeDesktop public async Task<(int[] updatesNeeded, int[] idErrors)> AboutToShowGroupAsync(int[] Ids) { - return (new int[0], new int[0]); + return (Array.Empty(), Array.Empty()); } #region Events diff --git a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs index ce210019c0..5c7ec2bbd2 100644 --- a/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs +++ b/src/Linux/Avalonia.LinuxFramebuffer/Output/DrmOutput.cs @@ -99,7 +99,7 @@ namespace Avalonia.LinuxFramebuffer.Output // prepare for the new ioctl call var handles = new uint[] {handle, 0, 0, 0}; var pitches = new uint[] {stride, 0, 0, 0}; - var offsets = new uint[] {}; + var offsets = Array.Empty(); var ret = drmModeAddFB2(_card.Fd, w, h, format, handles, pitches, offsets, out var fbHandle, 0);