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 <[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]>
  • Loading branch information
piyukore06 authored and targos committed Jan 13, 2020
1 parent cf19ec0 commit 08ac9b6
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 08ac9b6

Please sign in to comment.