From cb69ff47f665a8fe90d07f3ece123a0161f088f4 Mon Sep 17 00:00:00 2001 From: Priyanka Kore Date: Sun, 1 Dec 2019 14:35:18 +0100 Subject: [PATCH] src: improve node_crypto.cc memory allocation This avoids heap allocations in common cases PR-URL: https://github.com/nodejs/node/pull/30751 Reviewed-By: Anna Henningsen Reviewed-By: David Carlier Reviewed-By: Denys Otrishko Reviewed-By: James M Snell Reviewed-By: Colin Ihrig --- src/node_crypto.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index d1bd5471f3fba2..2d965bcbff5ea0 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -2697,11 +2697,11 @@ void SSLWrap::GetSharedSigalgs(const FunctionCallbackInfo& args) { Base* w; ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder()); Environment* env = w->ssl_env(); - std::vector> ret_arr; SSL* ssl = w->ssl_.get(); int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr); + MaybeStackBuffer, 16> ret_arr(nsig); for (int i = 0; i < nsig; i++) { int hash_nid; @@ -2765,12 +2765,11 @@ void SSLWrap::GetSharedSigalgs(const FunctionCallbackInfo& 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())); }