From 89cad7ed45603fed509b01f0c417f6f175aab9b9 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 3 Dec 2019 18:24:49 -0800 Subject: [PATCH] quic: additional suggested updates --- src/node_quic_session.cc | 29 +++++++++++++---------------- src/node_quic_session.h | 6 +++--- src/node_quic_stream.cc | 2 +- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/node_quic_session.cc b/src/node_quic_session.cc index 5b16d11b63..2e941e6501 100644 --- a/src/node_quic_session.cc +++ b/src/node_quic_session.cc @@ -223,7 +223,7 @@ void QuicSessionListener::OnOCSP(const std::string& ocsp) { void QuicSessionListener::OnStreamHeaders( int64_t stream_id, int kind, - std::vector>* headers) { + const std::vector>& headers) { if (previous_listener_ != nullptr) previous_listener_->OnStreamHeaders(stream_id, kind, headers); } @@ -375,29 +375,25 @@ void JSQuicSessionListener::OnCert(const char* server_name) { void JSQuicSessionListener::OnStreamHeaders( int64_t stream_id, int kind, - std::vector>* headers) { + const std::vector>& headers) { Environment* env = Session()->env(); HandleScope scope(env->isolate()); Context::Scope context_scope(env->context()); - std::vector> head; - for (const auto& header : *headers) { + MaybeStackBuffer, 16> head(headers.size()); + size_t n = 0; + for (const auto& header : headers) { // name and value should never be empty here, and if // they are, there's an actual bug so go ahead and crash Local pair[] = { header->GetName(Session()->Application()).ToLocalChecked(), header->GetValue(Session()->Application()).ToLocalChecked() }; - head.push_back(Array::New(env->isolate(), pair, arraysize(pair))); + head[n++] = Array::New(env->isolate(), pair, arraysize(pair)); } Local argv[] = { Number::New(env->isolate(), static_cast(stream_id)), - Array::New( - env->isolate(), - head.data(), - head.size()), - Integer::New( - env->isolate(), - kind) + Array::New(env->isolate(), head.out(), n), + Integer::New(env->isolate(), kind) }; BaseObjectPtr ptr(Session()); Session()->MakeCallback( @@ -641,16 +637,17 @@ void JSQuicSessionListener::OnVersionNegotiation( Local context = env->context(); Context::Scope context_scope(context); - std::vector> versions; + MaybeStackBuffer, 4> versions(vcnt); for (size_t n = 0; n < vcnt; n++) - versions.push_back(Integer::New(env->isolate(), vers[n])); + versions[n] = Integer::New(env->isolate(), vers[n]); + Local supported = Integer::New(env->isolate(), supported_version); Local argv[] = { Integer::New(env->isolate(), NGTCP2_PROTO_VER), - Array::New(env->isolate(), versions.data(), vcnt), + Array::New(env->isolate(), versions.out(), vcnt), Array::New(env->isolate(), &supported, 1) }; @@ -1110,7 +1107,7 @@ void QuicCryptoContext::WriteHandshake( void QuicApplication::StreamHeaders( int64_t stream_id, int kind, - std::vector>* headers) { + const std::vector>& headers) { Session()->Listener()->OnStreamHeaders(stream_id, kind, headers); } diff --git a/src/node_quic_session.h b/src/node_quic_session.h index c3c2b2cb6f..a6dd40976e 100644 --- a/src/node_quic_session.h +++ b/src/node_quic_session.h @@ -213,7 +213,7 @@ class QuicSessionListener { virtual void OnStreamHeaders( int64_t stream_id, int kind, - std::vector>* headers); + const std::vector>& headers); virtual void OnStreamClose( int64_t stream_id, uint64_t app_error_code); @@ -256,7 +256,7 @@ class JSQuicSessionListener : public QuicSessionListener { void OnStreamHeaders( int64_t stream_id, int kind, - std::vector>* headers) override; + const std::vector>& headers) override; void OnStreamClose( int64_t stream_id, uint64_t app_error_code) override; @@ -470,7 +470,7 @@ class QuicApplication : public MemoryRetainer { virtual void StreamHeaders( int64_t stream_id, int kind, - std::vector>* headers); + const std::vector>& headers); virtual void StreamClose( int64_t stream_id, uint64_t app_error_code); diff --git a/src/node_quic_stream.cc b/src/node_quic_stream.cc index 9dd9872a72..b5a11a953f 100644 --- a/src/node_quic_stream.cc +++ b/src/node_quic_stream.cc @@ -400,7 +400,7 @@ void QuicStream::EndHeaders() { // Upon completion of a block of headers, convert the // vector of Header objects into an array of name+value // pairs, then call the on_stream_headers function. - Session()->Application()->StreamHeaders(GetID(), headers_kind_, &headers_); + Session()->Application()->StreamHeaders(GetID(), headers_kind_, headers_); headers_.clear(); }