Skip to content

Commit 2f65b90

Browse files
authored
dns: reserve vector capacity in ParseTxtReply
The chunks vector's upper bound is known before the loop starts (str_count from ares_dns_rr_get_abin_cnt), so reserve the capacity upfront to avoid unnecessary reallocations. Signed-off-by: agape1225 <[email protected]> PR-URL: nodejs#64978 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Gürgün Dayıoğlu <[email protected]>
1 parent 536aca7 commit 2f65b90

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/cares_wrap.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ Maybe<int> ParseTxtReply(Environment* env,
644644
// Each TXT record is a chunk consisting of one or more character-strings.
645645
LocalVector<Value> chunks(env->isolate());
646646
size_t str_count = ares_dns_rr_get_abin_cnt(rr, ARES_RR_TXT_DATA);
647+
chunks.reserve(str_count);
647648
for (size_t j = 0; j < str_count; j++) {
648649
size_t str_len = 0;
649650
const unsigned char* str =

0 commit comments

Comments
 (0)