From c2b1271dbee202e0946d7ac0f7e8ee87b301efbd Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 10 Nov 2024 16:20:55 +0200 Subject: [PATCH] [UCRT] Improve __crt_seh_guarded_call This is a workaround for an MSVC compiler bug, which would result in degraded performance. See https://developercommunity.visualstudio.com/t/_local_unwind-generated-when-returning-f/10673261? --- sdk/lib/ucrt/inc/internal_shared.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/sdk/lib/ucrt/inc/internal_shared.h b/sdk/lib/ucrt/inc/internal_shared.h index 7ad4b4bafe3..a0f1a5a841e 100644 --- a/sdk/lib/ucrt/inc/internal_shared.h +++ b/sdk/lib/ucrt/inc/internal_shared.h @@ -206,10 +206,31 @@ struct __crt_seh_guarded_call template T operator()(Init init, Action action, Cleanup cleanup) { + T result; init(); __try { - return action(); + result = action(); + } + __finally + { + cleanup(); + } + __endtry + return result; + } +}; + +template<> +struct __crt_seh_guarded_call +{ + template + void operator()(Init init, Action action, Cleanup cleanup) + { + init(); + __try + { + action(); } __finally {