From 62bfb01e00dd4846ec5375addee2948e3b424c14 Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Mon, 10 Jun 2024 10:25:13 -0600 Subject: [PATCH] refactor: zend_call_stack_get_linux_pthread GCC doesn't pessimize the error cases correctly: https://godbolt.org/z/Pa6xsKMWc This speeds up the happy case and in this case the code size is also smaller, so it's a double-win. --- Zend/zend_call_stack.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/zend_call_stack.c b/Zend/zend_call_stack.c index 4228e2e75a9..a815801c0fe 100644 --- a/Zend/zend_call_stack.c +++ b/Zend/zend_call_stack.c @@ -133,12 +133,12 @@ static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) ZEND_ASSERT(!zend_call_stack_is_main_thread()); error = pthread_getattr_np(pthread_self(), &attr); - if (error) { + if (UNEXPECTED(error)) { return false; } error = pthread_attr_getstack(&attr, &addr, &max_size); - if (error) { + if (UNEXPECTED(error)) { pthread_attr_destroy(&attr); return false; } @@ -148,7 +148,7 @@ static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) size_t guard_size; /* In glibc prior to 2.8, addr and size include the guard pages */ error = pthread_attr_getguardsize(&attr, &guard_size); - if (error) { + if (UNEXPECTED(error)) { pthread_attr_destroy(&attr); return false; }