Skip to content

Commit c61cf02

Browse files
authored
Count poll and run branchlessly
Note: The same condition can be expressed by n += (~n > 0); or n += (~n != 0);
1 parent efdc25a commit c61cf02

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

asio/include/asio/detail/impl/win_iocp_io_context.ipp

+5-5
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ size_t win_iocp_io_context::run(asio::error_code& ec)
202202
thread_call_stack::context ctx(this, this_thread);
203203

204204
size_t n = 0;
205+
size_t loop_count_limit = (std::numeric_limits<size_t>::max)();
205206
while (do_one(INFINITE, this_thread, ec))
206-
if (n != (std::numeric_limits<size_t>::max)())
207-
++n;
207+
n += (n != loop_count_limit);
208208
return n;
209209
}
210210

@@ -251,9 +251,9 @@ size_t win_iocp_io_context::poll(asio::error_code& ec)
251251
thread_call_stack::context ctx(this, this_thread);
252252

253253
size_t n = 0;
254-
while (do_one(0, this_thread, ec))
255-
if (n != (std::numeric_limits<size_t>::max)())
256-
++n;
254+
size_t loop_count_limit = (std::numeric_limits<size_t>::max)();
255+
while (do_one(INFINITE, this_thread, ec))
256+
n += (n != loop_count_limit);
257257
return n;
258258
}
259259

0 commit comments

Comments
 (0)