From dc6909af0d0b470e3f89b6c09b4976f1f6793096 Mon Sep 17 00:00:00 2001 From: Alex Anderson Date: Fri, 13 Sep 2024 00:41:34 -0700 Subject: [PATCH] Count poll and run branchlessly Note: The same condition can be expressed by n += (~n > 0); or n += (~n != 0); --- asio/include/asio/detail/impl/win_iocp_io_context.ipp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/asio/include/asio/detail/impl/win_iocp_io_context.ipp b/asio/include/asio/detail/impl/win_iocp_io_context.ipp index 1c7fb28b2d..4e4c0eb55a 100644 --- a/asio/include/asio/detail/impl/win_iocp_io_context.ipp +++ b/asio/include/asio/detail/impl/win_iocp_io_context.ipp @@ -202,9 +202,9 @@ size_t win_iocp_io_context::run(asio::error_code& ec) thread_call_stack::context ctx(this, this_thread); size_t n = 0; + size_t loop_count_limit = (std::numeric_limits::max)(); while (do_one(INFINITE, this_thread, ec)) - if (n != (std::numeric_limits::max)()) - ++n; + n += (n != loop_count_limit); return n; } @@ -251,9 +251,9 @@ size_t win_iocp_io_context::poll(asio::error_code& ec) thread_call_stack::context ctx(this, this_thread); size_t n = 0; + size_t loop_count_limit = (std::numeric_limits::max)(); while (do_one(0, this_thread, ec)) - if (n != (std::numeric_limits::max)()) - ++n; + n += (n != loop_count_limit); return n; }