From c3fc4c91793464fd9a95d61fbc558459d3eedb95 Mon Sep 17 00:00:00 2001 From: jackarain Date: Mon, 23 Oct 2023 22:26:11 +0800 Subject: [PATCH] Improve happy_eyeballs_detection performance. --- proxy/include/proxy/async_connect.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/proxy/include/proxy/async_connect.hpp b/proxy/include/proxy/async_connect.hpp index 3286f336ad..1f3d002422 100644 --- a/proxy/include/proxy/async_connect.hpp +++ b/proxy/include/proxy/async_connect.hpp @@ -163,12 +163,15 @@ namespace asio_util { { bool has_a = false, has_aaaa = false; - for (auto begin_ = begin; begin_ != end; begin_++) + for (; begin != end && !(has_a && has_aaaa); begin++) { - const auto& addr = begin_->endpoint().address(); + const auto& addr = begin->endpoint().address(); - has_aaaa |= net::ip::address(addr).is_v6(); - has_a |= net::ip::address(addr).is_v4(); + if (!has_aaaa) + has_aaaa = addr.is_v6(); + + if (!has_a) + has_a = addr.is_v4(); } if (has_aaaa && has_a)