Skip to content

Commit bd380d5

Browse files
piyukore06BethGriggs
authored andcommitted
src: improve node_crypto.cc memory allocation
This avoids heap allocations in common cases PR-URL: #30751 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 19eb8e0 commit bd380d5

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/node_crypto.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -2700,11 +2700,11 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
27002700
Base* w;
27012701
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
27022702
Environment* env = w->ssl_env();
2703-
std::vector<Local<Value>> ret_arr;
27042703

27052704
SSL* ssl = w->ssl_.get();
27062705
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
27072706
nullptr);
2707+
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
27082708

27092709
for (int i = 0; i < nsig; i++) {
27102710
int hash_nid;
@@ -2768,12 +2768,11 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
27682768
} else {
27692769
sig_with_md += "UNDEF";
27702770
}
2771-
2772-
ret_arr.push_back(OneByteString(env->isolate(), sig_with_md.c_str()));
2771+
ret_arr[i] = OneByteString(env->isolate(), sig_with_md.c_str());
27732772
}
27742773

27752774
args.GetReturnValue().Set(
2776-
Array::New(env->isolate(), ret_arr.data(), ret_arr.size()));
2775+
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
27772776
}
27782777

27792778

0 commit comments

Comments
 (0)