Skip to content

Commit

Permalink
Slightly simplify and optimize ipv6_serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Nov 22, 2024
1 parent 1179c10 commit 5946edc
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/url_ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;) {
Expand Down

0 comments on commit 5946edc

Please sign in to comment.