From 4351b0a0cdcc295f36fb50f622d8d2619ee58095 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 26 Dec 2024 22:47:44 +1100 Subject: [PATCH 1/4] perf in LogMessage --- src/TestFramework/TestFramework/Logger.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Logger.cs b/src/TestFramework/TestFramework/Logger.cs index 46c4bbd224..ed875a0ed8 100644 --- a/src/TestFramework/TestFramework/Logger.cs +++ b/src/TestFramework/TestFramework/Logger.cs @@ -36,13 +36,34 @@ public static void LogMessage(string format, params object?[] args) Guard.NotNull(format); Guard.NotNull(args); + Delegate[] delegates = OnLogMessage.GetInvocationList(); + + if (delegates.Length == 0) + { + return; + } + string message = args.Length == 0 ? format : string.Format(CultureInfo.InvariantCulture, format, args); + if (delegates.Length == 1) + { + try + { + OnLogMessage(message); + } + catch (Exception) + { + // Catch and ignore all exceptions thrown by event handlers. + } + + return; + } + object?[] parameters = [message]; // Making sure all event handlers are called in sync on same thread. - foreach (Delegate invoker in OnLogMessage.GetInvocationList()) + foreach (Delegate invoker in delegates) { try { From 006b903cf72bba757097b3cbfb1cdc99eddb7710 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 27 Dec 2024 21:00:04 +1100 Subject: [PATCH 2/4] Update Logger.cs --- src/TestFramework/TestFramework/Logger.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/TestFramework/TestFramework/Logger.cs b/src/TestFramework/TestFramework/Logger.cs index ed875a0ed8..289c9a2159 100644 --- a/src/TestFramework/TestFramework/Logger.cs +++ b/src/TestFramework/TestFramework/Logger.cs @@ -38,11 +38,6 @@ public static void LogMessage(string format, params object?[] args) Delegate[] delegates = OnLogMessage.GetInvocationList(); - if (delegates.Length == 0) - { - return; - } - string message = args.Length == 0 ? format : string.Format(CultureInfo.InvariantCulture, format, args); From 5ef3b84c0d33d58d8158dbf659735fab494f4dce Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 27 Dec 2024 22:16:21 +1100 Subject: [PATCH 3/4] . --- Directory.Packages.props | 2 +- src/TestFramework/TestFramework/Logger.cs | 21 ++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 2ab7b2733f..72ae1578c6 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -46,7 +46,7 @@ - + diff --git a/src/TestFramework/TestFramework/Logger.cs b/src/TestFramework/TestFramework/Logger.cs index 289c9a2159..c2c976405d 100644 --- a/src/TestFramework/TestFramework/Logger.cs +++ b/src/TestFramework/TestFramework/Logger.cs @@ -36,33 +36,16 @@ public static void LogMessage(string format, params object?[] args) Guard.NotNull(format); Guard.NotNull(args); - Delegate[] delegates = OnLogMessage.GetInvocationList(); - string message = args.Length == 0 ? format : string.Format(CultureInfo.InvariantCulture, format, args); - if (delegates.Length == 1) - { - try - { - OnLogMessage(message); - } - catch (Exception) - { - // Catch and ignore all exceptions thrown by event handlers. - } - - return; - } - - object?[] parameters = [message]; // Making sure all event handlers are called in sync on same thread. - foreach (Delegate invoker in delegates) + foreach (LogMessageHandler invoker in DelegatePolyfill.EnumerateInvocationList(OnLogMessage)) { try { - invoker.GetMethodInfo()!.Invoke(invoker.Target, parameters); + invoker(message); } catch (Exception) { From aeaa33ebf2e4a8954848a614530875d6efa908bc Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 28 Dec 2024 20:24:45 +1100 Subject: [PATCH 4/4] Update Directory.Packages.props --- Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 0b1b01808d..0801dc85be 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -46,7 +46,7 @@ - +