@@ -224,7 +224,7 @@ void QuicSessionListener::OnOCSP(const std::string& ocsp) {
224224void QuicSessionListener::OnStreamHeaders (
225225 int64_t stream_id,
226226 int kind,
227- std::vector<std::unique_ptr<QuicHeader>>* headers) {
227+ const std::vector<std::unique_ptr<QuicHeader>>& headers) {
228228 if (previous_listener_ != nullptr )
229229 previous_listener_->OnStreamHeaders (stream_id, kind, headers);
230230}
@@ -376,29 +376,25 @@ void JSQuicSessionListener::OnCert(const char* server_name) {
376376void JSQuicSessionListener::OnStreamHeaders (
377377 int64_t stream_id,
378378 int kind,
379- std::vector<std::unique_ptr<QuicHeader>>* headers) {
379+ const std::vector<std::unique_ptr<QuicHeader>>& headers) {
380380 Environment* env = Session ()->env ();
381381 HandleScope scope (env->isolate ());
382382 Context::Scope context_scope (env->context ());
383- std::vector<Local<Value>> head;
384- for (const auto & header : *headers) {
383+ MaybeStackBuffer<Local<Value>, 16 > head (headers.size ());
384+ size_t n = 0 ;
385+ for (const auto & header : headers) {
385386 // name and value should never be empty here, and if
386387 // they are, there's an actual bug so go ahead and crash
387388 Local<Value> pair[] = {
388389 header->GetName (Session ()->Application ()).ToLocalChecked (),
389390 header->GetValue (Session ()->Application ()).ToLocalChecked ()
390391 };
391- head. push_back ( Array::New (env->isolate (), pair, arraysize (pair) ));
392+ head[n++] = Array::New (env->isolate (), pair, arraysize (pair));
392393 }
393394 Local<Value> argv[] = {
394395 Number::New (env->isolate (), static_cast <double >(stream_id)),
395- Array::New (
396- env->isolate (),
397- head.data (),
398- head.size ()),
399- Integer::New (
400- env->isolate (),
401- kind)
396+ Array::New (env->isolate (), head.out (), n),
397+ Integer::New (env->isolate (), kind)
402398 };
403399 BaseObjectPtr<QuicSession> ptr (Session ());
404400 Session ()->MakeCallback (
@@ -643,16 +639,17 @@ void JSQuicSessionListener::OnVersionNegotiation(
643639 Local<Context> context = env->context ();
644640 Context::Scope context_scope (context);
645641
646- std::vector <Local<Value>> versions;
642+ MaybeStackBuffer <Local<Value>, 4 > versions (vcnt) ;
647643 for (size_t n = 0 ; n < vcnt; n++)
648- versions.push_back (Integer::New (env->isolate (), vers[n]));
644+ versions[n] = Integer::New (env->isolate (), vers[n]);
645+
649646
650647 Local<Value> supported =
651648 Integer::New (env->isolate (), supported_version);
652649
653650 Local<Value> argv[] = {
654651 Integer::New (env->isolate (), NGTCP2_PROTO_VER),
655- Array::New (env->isolate (), versions.data (), vcnt),
652+ Array::New (env->isolate (), versions.out (), vcnt),
656653 Array::New (env->isolate (), &supported, 1 )
657654 };
658655
@@ -1115,7 +1112,7 @@ void QuicCryptoContext::WriteHandshake(
11151112void QuicApplication::StreamHeaders (
11161113 int64_t stream_id,
11171114 int kind,
1118- std::vector<std::unique_ptr<QuicHeader>>* headers) {
1115+ const std::vector<std::unique_ptr<QuicHeader>>& headers) {
11191116 Session ()->Listener ()->OnStreamHeaders (stream_id, kind, headers);
11201117}
11211118
0 commit comments