From bd15275bb33b33d49dedb96b6455358776c2c896 Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Thu, 14 Jan 2016 08:41:58 -0600 Subject: [PATCH] src: cares_wrap: only loop through once on lookup The results will already be sorted based on the implementation of getaddrinfo(). There is no need to loop through the returned addresses twice (once for IPv4, once for IPv6). We should return them in the order in which they already are. --- src/cares_wrap.cc | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 8f57dfe477cda4..9765e301ac1ec5 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -928,7 +928,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { char ip[INET6_ADDRSTRLEN]; const char *addr; - // Iterate over the IPv4 responses again this time creating javascript + // Iterate over the IPv4/IPv6 responses again this time creating javascript // strings for each IP and filling the results array. address = res; while (address) { @@ -950,20 +950,7 @@ void AfterGetAddrInfo(uv_getaddrinfo_t* req, int status, struct addrinfo* res) { Local s = OneByteString(env->isolate(), ip); results->Set(n, s); n++; - } - - // Increment - address = address->ai_next; - } - - // Iterate over the IPv6 responses putting them in the array. - address = res; - while (address) { - CHECK_EQ(address->ai_socktype, SOCK_STREAM); - - // Ignore random ai_family types. - if (address->ai_family == AF_INET6) { - // Juggle pointers + } else if (address->ai_family == AF_INET6) { addr = reinterpret_cast(&(reinterpret_cast( address->ai_addr)->sin6_addr)); int err = uv_inet_ntop(address->ai_family,