From 5946edcd9b5c6590de191c91ea9499516a352982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Fri, 22 Nov 2024 21:38:56 +0200 Subject: [PATCH] Slightly simplify and optimize ipv6_serialize --- src/url_ip.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/url_ip.cpp b/src/url_ip.cpp index 7c7452b..1504b8d 100644 --- a/src/url_ip.cpp +++ b/src/url_ip.cpp @@ -24,11 +24,12 @@ void ipv4_serialize(uint32_t ipv4, std::string& output) { namespace { -std::size_t longest_zero_sequence( +inline std::size_t longest_zero_sequence( const uint16_t* first, const uint16_t* last, const uint16_t*& compress) { - std::size_t last_count = 0; + // The sequence to compress should be longer than 1 zero + std::size_t last_count = 1; for (auto it = first; it != last; ++it) { if (*it == 0) { auto ite = it + 1; @@ -53,8 +54,6 @@ void ipv6_serialize(const uint16_t(&address)[8], std::string& output) { const uint16_t *compress = nullptr; const auto compress_length = longest_zero_sequence(first, last, compress); - if (compress_length == 1) - compress = nullptr; // "it" pointer corresponds to pieceIndex in the URL standard for (auto it = first; true;) {