Skip to content

Commit

Permalink
src: improve node_crypto.cc memory allocation
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
piyukore06 authored and targos committed Dec 9, 2019
1 parent b51b26f commit cb69ff4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2697,11 +2697,11 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
Base* w;
ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder());
Environment* env = w->ssl_env();
std::vector<Local<Value>> ret_arr;

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

for (int i = 0; i < nsig; i++) {
int hash_nid;
Expand Down Expand Up @@ -2765,12 +2765,11 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) {
} else {
sig_with_md += "UNDEF";
}

ret_arr.push_back(OneByteString(env->isolate(), sig_with_md.c_str()));
ret_arr[i] = OneByteString(env->isolate(), sig_with_md.c_str());
}

args.GetReturnValue().Set(
Array::New(env->isolate(), ret_arr.data(), ret_arr.size()));
Array::New(env->isolate(), ret_arr.out(), ret_arr.length()));
}


Expand Down

0 comments on commit cb69ff4

Please sign in to comment.