Skip to content

Commit 08ac9b6

Browse files
piyukore06targos
authored andcommitted
src: improve node_crypto.cc memory allocation
This avoids heap allocations in common cases PR-URL: #30751 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent cf19ec0 commit 08ac9b6

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
@@ -2697,11 +2697,11 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
26972697
Base* w;
26982698
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
26992699
Environment* env = w->ssl_env();
2700-
std::vector<Local<Value>> ret_arr;
27012700

27022701
SSL* ssl = w->ssl_.get();
27032702
int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr,
27042703
nullptr);
2704+
MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig);
27052705

27062706
for (int i = 0; i < nsig; i++) {
27072707
int hash_nid;
@@ -2765,12 +2765,11 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
27652765
} else {
27662766
sig_with_md += "UNDEF";
27672767
}
2768-
2769-
ret_arr.push_back(OneByteString(env->isolate(), sig_with_md.c_str()));
2768+
ret_arr[i] = OneByteString(env->isolate(), sig_with_md.c_str());
27702769
}
27712770

27722771
args.GetReturnValue().Set(
2773-
Array::New(env->isolate(), ret_arr.data(), ret_arr.size()));
2772+
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
27742773
}
27752774

27762775

0 commit comments

Comments
 (0)