Browse Source

perf: remove some closure (#14050)

Avoid allocating a new object to pass the argument to the anonymous delegate
pull/14089/head
workgroupengineering 2 years ago
committed by GitHub
parent
commit
d0f38218b7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Avalonia.Controls/Remote/RemoteWidget.cs
  2. 12
      src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs
  3. 12
      src/Avalonia.Native/AvaloniaNativeMenuExporter.cs
  4. 31
      src/Avalonia.X11/X11PlatformLifetimeEvents.cs

4
src/Avalonia.Controls/Remote/RemoteWidget.cs

@ -26,7 +26,7 @@ namespace Avalonia.Controls.Remote
Mode = SizingMode.Local;
_connection = connection;
_connection.OnMessage += (t, msg) => Dispatcher.UIThread.Post(() => OnMessage(msg));
_connection.OnMessage += (t, msg) => Dispatcher.UIThread.Post(OnMessage, msg);
_connection.Send(new ClientSupportedPixelFormatsMessage
{
Formats = new[]
@ -39,7 +39,7 @@ namespace Avalonia.Controls.Remote
public SizingMode Mode { get; set; }
private void OnMessage(object msg)
private void OnMessage(object? msg)
{
if (msg is FrameMessage frame)
{

12
src/Avalonia.DesignerSupport/Remote/RemoteDesignerEntryPoint.cs

@ -202,24 +202,24 @@ namespace Avalonia.DesignerSupport.Remote
}
private static Window s_currentWindow;
private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.Post(() =>
private static void OnTransportMessage(IAvaloniaRemoteTransportConnection transport, object obj) => Dispatcher.UIThread.Post(static arg =>
{
if (obj is ClientSupportedPixelFormatsMessage formats)
if (arg is ClientSupportedPixelFormatsMessage formats)
{
s_supportedPixelFormats = formats;
RebuildPreFlight();
}
if (obj is ClientRenderInfoMessage renderInfo)
if (arg is ClientRenderInfoMessage renderInfo)
{
s_renderInfoMessage = renderInfo;
RebuildPreFlight();
}
if (obj is ClientViewportAllocatedMessage viewport)
if (arg is ClientViewportAllocatedMessage viewport)
{
s_viewportAllocatedMessage = viewport;
RebuildPreFlight();
}
if (obj is UpdateXamlMessage xaml)
if (arg is UpdateXamlMessage xaml)
{
if (s_currentWindow is not null)
s_lastRenderScaling = s_currentWindow.RenderScaling;
@ -247,6 +247,6 @@ namespace Avalonia.DesignerSupport.Remote
});
}
}
});
}, obj);
}
}

12
src/Avalonia.Native/AvaloniaNativeMenuExporter.cs

@ -146,6 +146,8 @@ namespace Avalonia.Native
appMenu.Add(quitItem);
}
private void DoLayoutReset() => DoLayoutReset(false);
private void DoLayoutReset(bool forceUpdate = false)
{
var macOpts = AvaloniaLocator.Current.GetService<MacOSPlatformOptions>() ?? new MacOSPlatformOptions();
@ -195,7 +197,7 @@ namespace Avalonia.Native
if (_resetQueued)
return;
_resetQueued = true;
Dispatcher.UIThread.Post(() => DoLayoutReset(), DispatcherPriority.Background);
Dispatcher.UIThread.Post(DoLayoutReset, DispatcherPriority.Background);
}
private void SetMenu(NativeMenu menu)
@ -252,9 +254,9 @@ namespace Avalonia.Native
{
_nativeMenu = __MicroComIAvnMenuProxy.Create(_factory);
_nativeMenu.Initialize(this, menu, "");
_nativeMenu.Initialize(this, menu, "");
setMenu = true;
setMenu = true;
}
_nativeMenu.Update(_factory, menu);
@ -273,9 +275,9 @@ namespace Avalonia.Native
{
_nativeMenu = __MicroComIAvnMenuProxy.Create(_factory);
_nativeMenu.Initialize(this, menu, "");
_nativeMenu.Initialize(this, menu, "");
setMenu = true;
setMenu = true;
}
_nativeMenu.Update(_factory, menu);

31
src/Avalonia.X11/X11PlatformLifetimeEvents.cs

@ -223,28 +223,31 @@ namespace Avalonia.X11
private void InteractHandler(IntPtr smcConn)
{
Dispatcher.UIThread.Post(() => ActualInteractHandler(smcConn));
Dispatcher.UIThread.Post(ActualInteractHandler, smcConn);
}
private void ActualInteractHandler(IntPtr smcConn)
private void ActualInteractHandler(object? state)
{
var e = new ShutdownRequestedEventArgs();
if (_platform.Options?.EnableSessionManagement ?? false)
if (state is IntPtr smcConn)
{
ShutdownRequested?.Invoke(this, e);
}
var e = new ShutdownRequestedEventArgs();
SMLib.SmcInteractDone(smcConn, e.Cancel);
if (_platform.Options?.EnableSessionManagement ?? false)
{
ShutdownRequested?.Invoke(this, e);
}
if (e.Cancel)
{
return;
}
SMLib.SmcInteractDone(smcConn, e.Cancel);
_saveYourselfPhase = false;
if (e.Cancel)
{
return;
}
_saveYourselfPhase = false;
SMLib.SmcSaveYourselfDone(smcConn, true);
SMLib.SmcSaveYourselfDone(smcConn, true);
}
}
private static void IceWatchHandler(IntPtr iceConn, IntPtr clientData, bool opening, IntPtr* watchData)

Loading…
Cancel
Save