Skip to content

Commit be75795

Browse files
maclover7targos
authored andcommitted
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: #21876 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent d9cd171 commit be75795

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

src/cares_wrap.cc

+21-36
Original file line numberDiff line numberDiff line change
@@ -856,23 +856,20 @@ int ParseMxReply(Environment* env,
856856
return status;
857857
}
858858

859-
Local<String> exchange_symbol = env->exchange_string();
860-
Local<String> priority_symbol = env->priority_string();
861-
Local<String> type_symbol = env->type_string();
862-
Local<String> mx_symbol = env->dns_mx_string();
863-
864859
uint32_t offset = ret->Length();
865860
ares_mx_reply* current = mx_start;
866861
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
867862
Local<Object> mx_record = Object::New(env->isolate());
868863
mx_record->Set(context,
869-
exchange_symbol,
864+
env->exchange_string(),
870865
OneByteString(env->isolate(), current->host)).FromJust();
871866
mx_record->Set(context,
872-
priority_symbol,
867+
env->priority_string(),
873868
Integer::New(env->isolate(), current->priority)).FromJust();
874869
if (need_type)
875-
mx_record->Set(context, type_symbol, mx_symbol).FromJust();
870+
mx_record->Set(context,
871+
env->type_string(),
872+
env->dns_mx_string()).FromJust();
876873

877874
ret->Set(context, i + offset, mx_record).FromJust();
878875
}
@@ -959,31 +956,26 @@ int ParseSrvReply(Environment* env,
959956
return status;
960957
}
961958

962-
Local<String> name_symbol = env->name_string();
963-
Local<String> port_symbol = env->port_string();
964-
Local<String> priority_symbol = env->priority_string();
965-
Local<String> weight_symbol = env->weight_string();
966-
Local<String> type_symbol = env->type_string();
967-
Local<String> srv_symbol = env->dns_srv_string();
968-
969959
ares_srv_reply* current = srv_start;
970960
int offset = ret->Length();
971961
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
972962
Local<Object> srv_record = Object::New(env->isolate());
973963
srv_record->Set(context,
974-
name_symbol,
964+
env->name_string(),
975965
OneByteString(env->isolate(), current->host)).FromJust();
976966
srv_record->Set(context,
977-
port_symbol,
967+
env->port_string(),
978968
Integer::New(env->isolate(), current->port)).FromJust();
979969
srv_record->Set(context,
980-
priority_symbol,
970+
env->priority_string(),
981971
Integer::New(env->isolate(), current->priority)).FromJust();
982972
srv_record->Set(context,
983-
weight_symbol,
973+
env->weight_string(),
984974
Integer::New(env->isolate(), current->weight)).FromJust();
985975
if (need_type)
986-
srv_record->Set(context, type_symbol, srv_symbol).FromJust();
976+
srv_record->Set(context,
977+
env->type_string(),
978+
env->dns_srv_string()).FromJust();
987979

988980
ret->Set(context, i + offset, srv_record).FromJust();
989981
}
@@ -1008,43 +1000,36 @@ int ParseNaptrReply(Environment* env,
10081000
return status;
10091001
}
10101002

1011-
Local<String> flags_symbol = env->flags_string();
1012-
Local<String> service_symbol = env->service_string();
1013-
Local<String> regexp_symbol = env->regexp_string();
1014-
Local<String> replacement_symbol = env->replacement_string();
1015-
Local<String> order_symbol = env->order_string();
1016-
Local<String> preference_symbol = env->preference_string();
1017-
Local<String> type_symbol = env->type_string();
1018-
Local<String> naptr_symbol = env->dns_naptr_string();
1019-
10201003
ares_naptr_reply* current = naptr_start;
10211004
int offset = ret->Length();
10221005
for (uint32_t i = 0; current != nullptr; ++i, current = current->next) {
10231006
Local<Object> naptr_record = Object::New(env->isolate());
10241007
naptr_record->Set(context,
1025-
flags_symbol,
1008+
env->flags_string(),
10261009
OneByteString(env->isolate(), current->flags)).FromJust();
10271010
naptr_record->Set(context,
1028-
service_symbol,
1011+
env->service_string(),
10291012
OneByteString(env->isolate(),
10301013
current->service)).FromJust();
10311014
naptr_record->Set(context,
1032-
regexp_symbol,
1015+
env->regexp_string(),
10331016
OneByteString(env->isolate(),
10341017
current->regexp)).FromJust();
10351018
naptr_record->Set(context,
1036-
replacement_symbol,
1019+
env->replacement_string(),
10371020
OneByteString(env->isolate(),
10381021
current->replacement)).FromJust();
10391022
naptr_record->Set(context,
1040-
order_symbol,
1023+
env->order_string(),
10411024
Integer::New(env->isolate(), current->order)).FromJust();
10421025
naptr_record->Set(context,
1043-
preference_symbol,
1026+
env->preference_string(),
10441027
Integer::New(env->isolate(),
10451028
current->preference)).FromJust();
10461029
if (need_type)
1047-
naptr_record->Set(context, type_symbol, naptr_symbol).FromJust();
1030+
naptr_record->Set(context,
1031+
env->type_string(),
1032+
env->dns_naptr_string()).FromJust();
10481033

10491034
ret->Set(context, i + offset, naptr_record).FromJust();
10501035
}

0 commit comments

Comments
 (0)