From be757958684cca2d0f51b82baef1ab34ae8d21b9 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Wed, 18 Jul 2018 19:54:38 -0400 Subject: [PATCH] src: don't store one-use strings in variable Move strings that are used only once to their call-sites, don't store in a variable. PR-URL: https://github.com/nodejs/node/pull/21876 Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen Reviewed-By: Trivikram Kamat Reviewed-By: Minwoo Jung Reviewed-By: James M Snell Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Colin Ihrig --- src/cares_wrap.cc | 57 +++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 69a3d46668193a..604213a2c65934 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -856,23 +856,20 @@ int ParseMxReply(Environment* env, return status; } - Local exchange_symbol = env->exchange_string(); - Local priority_symbol = env->priority_string(); - Local type_symbol = env->type_string(); - Local mx_symbol = env->dns_mx_string(); - uint32_t offset = ret->Length(); ares_mx_reply* current = mx_start; for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { Local mx_record = Object::New(env->isolate()); mx_record->Set(context, - exchange_symbol, + env->exchange_string(), OneByteString(env->isolate(), current->host)).FromJust(); mx_record->Set(context, - priority_symbol, + env->priority_string(), Integer::New(env->isolate(), current->priority)).FromJust(); if (need_type) - mx_record->Set(context, type_symbol, mx_symbol).FromJust(); + mx_record->Set(context, + env->type_string(), + env->dns_mx_string()).FromJust(); ret->Set(context, i + offset, mx_record).FromJust(); } @@ -959,31 +956,26 @@ int ParseSrvReply(Environment* env, return status; } - Local name_symbol = env->name_string(); - Local port_symbol = env->port_string(); - Local priority_symbol = env->priority_string(); - Local weight_symbol = env->weight_string(); - Local type_symbol = env->type_string(); - Local srv_symbol = env->dns_srv_string(); - ares_srv_reply* current = srv_start; int offset = ret->Length(); for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { Local srv_record = Object::New(env->isolate()); srv_record->Set(context, - name_symbol, + env->name_string(), OneByteString(env->isolate(), current->host)).FromJust(); srv_record->Set(context, - port_symbol, + env->port_string(), Integer::New(env->isolate(), current->port)).FromJust(); srv_record->Set(context, - priority_symbol, + env->priority_string(), Integer::New(env->isolate(), current->priority)).FromJust(); srv_record->Set(context, - weight_symbol, + env->weight_string(), Integer::New(env->isolate(), current->weight)).FromJust(); if (need_type) - srv_record->Set(context, type_symbol, srv_symbol).FromJust(); + srv_record->Set(context, + env->type_string(), + env->dns_srv_string()).FromJust(); ret->Set(context, i + offset, srv_record).FromJust(); } @@ -1008,43 +1000,36 @@ int ParseNaptrReply(Environment* env, return status; } - Local flags_symbol = env->flags_string(); - Local service_symbol = env->service_string(); - Local regexp_symbol = env->regexp_string(); - Local replacement_symbol = env->replacement_string(); - Local order_symbol = env->order_string(); - Local preference_symbol = env->preference_string(); - Local type_symbol = env->type_string(); - Local naptr_symbol = env->dns_naptr_string(); - ares_naptr_reply* current = naptr_start; int offset = ret->Length(); for (uint32_t i = 0; current != nullptr; ++i, current = current->next) { Local naptr_record = Object::New(env->isolate()); naptr_record->Set(context, - flags_symbol, + env->flags_string(), OneByteString(env->isolate(), current->flags)).FromJust(); naptr_record->Set(context, - service_symbol, + env->service_string(), OneByteString(env->isolate(), current->service)).FromJust(); naptr_record->Set(context, - regexp_symbol, + env->regexp_string(), OneByteString(env->isolate(), current->regexp)).FromJust(); naptr_record->Set(context, - replacement_symbol, + env->replacement_string(), OneByteString(env->isolate(), current->replacement)).FromJust(); naptr_record->Set(context, - order_symbol, + env->order_string(), Integer::New(env->isolate(), current->order)).FromJust(); naptr_record->Set(context, - preference_symbol, + env->preference_string(), Integer::New(env->isolate(), current->preference)).FromJust(); if (need_type) - naptr_record->Set(context, type_symbol, naptr_symbol).FromJust(); + naptr_record->Set(context, + env->type_string(), + env->dns_naptr_string()).FromJust(); ret->Set(context, i + offset, naptr_record).FromJust(); }