From 90b84f3d1131ad9c8370d7f4356c9291f3ff45ee Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 25 Jun 2021 16:48:48 -0400 Subject: [PATCH] Remove delegate/closure/array allocations from EventMap.NotifySources --- .../MS/internal/Automation/EventMap.cs | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/EventMap.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/EventMap.cs index 2dc14212e09..cfb075e7ca2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/EventMap.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/EventMap.cs @@ -269,26 +269,21 @@ private static void NotifySources() { if (!source.IsDisposed) { - source.Dispatcher.BeginInvoke(DispatcherPriority.Normal, - new DispatcherOperationCallback(NotifySource), - new object[]{source}); + source.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (DispatcherOperationCallback)(state => + { + PresentationSource source = (PresentationSource)state; + if (source != null && !source.IsDisposed) + { + // setting the RootVisual to itself triggers the logic to + // add to the AutomationEvents list + source.RootVisual = source.RootVisual; + } + return null; + }), source); } } } - private static object NotifySource(Object args) - { - object[] argsArray = (object[])args; - PresentationSource source = argsArray[0] as PresentationSource; - if (source != null && !source.IsDisposed) - { - // setting the RootVisual to itself triggers the logic to - // add to the AutomationEvents list - source.RootVisual = source.RootVisual; - } - return null; - } - private static Hashtable _eventsTable; // key=event id, data=listener count private readonly static object _lock = new object(); }