From fc6400a1ef599ae3eb04512e5deffc547f9e95ef Mon Sep 17 00:00:00 2001 From: Christopher Kohlhoff Date: Mon, 2 Nov 2020 12:47:56 +1100 Subject: [PATCH] Restore null pointer check for better performance. --- include/boost/asio/detail/thread_info_base.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/boost/asio/detail/thread_info_base.hpp b/include/boost/asio/detail/thread_info_base.hpp index a05320ab..35c03cbb 100644 --- a/include/boost/asio/detail/thread_info_base.hpp +++ b/include/boost/asio/detail/thread_info_base.hpp @@ -66,7 +66,13 @@ public: ~thread_info_base() { for (int i = 0; i < max_mem_index; ++i) - ::operator delete(reusable_memory_[i]); + { + // The following test for non-null pointers is technically redundant, but + // it is significantly faster when using a tight io_context::poll() loop + // in latency sensitive applications. + if (reusable_memory_[i]) + ::operator delete(reusable_memory_[i]); + } } static void* allocate(thread_info_base* this_thread, std::size_t size)