Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly simplify and optimize ipv6_serialize #85

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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