From fc4c0b09ca93b5857e329f1dcfc33fdc52d98def Mon Sep 17 00:00:00 2001 From: Jumar Macato <16554748+jmacato@users.noreply.github.com> Date: Wed, 27 Oct 2021 00:34:40 +0800 Subject: [PATCH] make the icon converter delegate static to avoid unnecessary allocs --- src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs | 2 +- src/Avalonia.X11/X11Platform.cs | 22 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs b/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs index c7ff775d6f..58e8a8efc8 100644 --- a/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs +++ b/src/Avalonia.FreeDesktop/DBusTrayIconImpl.cs @@ -41,7 +41,7 @@ namespace Avalonia.FreeDesktop public bool IsActive { get; private set; } public INativeMenuExporter? MenuExporter { get; } public Action? OnClicked { get; set; } - public Func? IconConverterDelegate { get; set; } + public Func IconConverterDelegate { get; set; } public DBusTrayIconImpl() { diff --git a/src/Avalonia.X11/X11Platform.cs b/src/Avalonia.X11/X11Platform.cs index 452a72bc83..a2bd57404b 100644 --- a/src/Avalonia.X11/X11Platform.cs +++ b/src/Avalonia.X11/X11Platform.cs @@ -105,23 +105,25 @@ namespace Avalonia.X11 public IntPtr DeferredDisplay { get; set; } public IntPtr Display { get; set; } - public ITrayIconImpl CreateTrayIcon () + private static uint[] X11IconConverter(IWindowIconImpl? icon) + { + if (!(icon is X11IconData x11icon)) + return Array.Empty(); + + return x11icon.Data.Select(x => x.ToUInt32()).ToArray(); + } + + public ITrayIconImpl CreateTrayIcon() { var dbusTrayIcon = new DBusTrayIconImpl(); if (!dbusTrayIcon.IsActive) return new XEmbedTrayIconImpl(); - - dbusTrayIcon.IconConverterDelegate = (icon) => - { - if (!(icon is X11IconData x11icon)) - return Array.Empty(); - return x11icon.Data.Select(x=>x.ToUInt32()).ToArray(); - }; - + dbusTrayIcon.IconConverterDelegate = X11IconConverter; + return dbusTrayIcon; } - + public IWindowImpl CreateWindow() { return new X11Window(this, null);