Skip to content

Commit 98dc554

Browse files
bnoordhuisMylesBorins
authored andcommitted
src: inline HostentToAddresses()
With the removal of `GetHostByNameWrap` in the previous commit, there is only one remaining call site. Inlining it there lets us simplify the logic. PR-URL: #17860 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]>
1 parent 87b336a commit 98dc554

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/cares_wrap.cc

+9-24
Original file line numberDiff line numberDiff line change
@@ -367,26 +367,6 @@ void ares_sockstate_cb(void* data,
367367
}
368368

369369

370-
Local<Array> HostentToAddresses(Environment* env,
371-
struct hostent* host,
372-
Local<Array> append_to = Local<Array>()) {
373-
EscapableHandleScope scope(env->isolate());
374-
auto context = env->context();
375-
bool append = !append_to.IsEmpty();
376-
Local<Array> addresses = append ? append_to : Array::New(env->isolate());
377-
size_t offset = addresses->Length();
378-
379-
char ip[INET6_ADDRSTRLEN];
380-
for (uint32_t i = 0; host->h_addr_list[i] != nullptr; ++i) {
381-
uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip));
382-
Local<String> address = OneByteString(env->isolate(), ip);
383-
addresses->Set(context, i + offset, address).FromJust();
384-
}
385-
386-
return append ? addresses : scope.Escape(addresses);
387-
}
388-
389-
390370
Local<Array> HostentToNames(Environment* env,
391371
struct hostent* host,
392372
Local<Array> append_to = Local<Array>()) {
@@ -843,12 +823,17 @@ int ParseGeneralReply(Environment* env,
843823
} else if (*type == ns_t_ptr) {
844824
uint32_t offset = ret->Length();
845825
for (uint32_t i = 0; host->h_aliases[i] != nullptr; i++) {
846-
ret->Set(context,
847-
i + offset,
848-
OneByteString(env->isolate(), host->h_aliases[i])).FromJust();
826+
auto alias = OneByteString(env->isolate(), host->h_aliases[i]);
827+
ret->Set(context, i + offset, alias).FromJust();
849828
}
850829
} else {
851-
HostentToAddresses(env, host, ret);
830+
uint32_t offset = ret->Length();
831+
char ip[INET6_ADDRSTRLEN];
832+
for (uint32_t i = 0; host->h_addr_list[i] != nullptr; ++i) {
833+
uv_inet_ntop(host->h_addrtype, host->h_addr_list[i], ip, sizeof(ip));
834+
auto address = OneByteString(env->isolate(), ip);
835+
ret->Set(context, i + offset, address).FromJust();
836+
}
852837
}
853838

854839
ares_free_hostent(host);

0 commit comments

Comments
 (0)